您的位置:首页 > Web前端 > React

react-native生命周期

2017-10-07 16:15 417 查看
//初始化
constructor(props) {
super(props);
console.log('---------constructor--------')
}
//组件将要加载,整个生命周期只执行一次,在render方法之前执行
componentWillMount() {
console.log('---------componentWillMount--------')

}
//组件已经加载,在render方法之后执行,整个生命周期只执行一次
componentDidMount() {
console.log('---------componentDidMount--------')

}
//在组件接收到其父组件传递的props的时候执行,参数为父组件传递的props。在组件的整个生命周期可以多次执行
componentWillReceiveProps(nextProps) {
console.log('---------componentWillReceiveProps--------')
this.setState({
//key : value
});
}
//在componentWillReceiveProps(nextProps)执行之后立刻执行;或者在state更改之后立刻执行
shouldComponentUpdate(nextProps, nextState) {
console.log('---------shouldComponentUpdate--------')
return true;
}
//在shouldComponentUpdate(nextProps, nextState)函数执行完毕之后立刻调用,该方法包含两个参数
componentWillUpdate(nextProps, nextState) {
console.log('---------componentWillUpdate--------')

}

//在render()方法执行之后立刻调用。该方法包含两个参数,分别是props和state
componentDidUpdate(preProps, preState) {
console.log('---------componentDidUpdate--------')

}

//render方法用于渲染组件。在初始化阶段和运行期阶段都会执行。
render() {
console.log('---------render--------')
return (
<Tex></Text>
);
}

//在组件由虚拟DOM卸载的时候调用
componentWillUnmount() {
console.log('---------componentWillUnmount--------')

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  生命周期