react-native生命周期

来源:互联网 发布:ubuntu16.04启动mysql 编辑:程序博客网 时间:2024/06/03 16:43
//初始化    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--------')    }