生命周期函数指在某一个时刻组件会自动调用执行的函数;
componentWillMount(){ console.log('1')} 在组件即将被挂载到页面的时刻自动执行
componentDidMount(){console.log('2')} 组件被挂载到页面之后,自动被执行
shouldComponentUpdate(){console.log('3')} 组件被更新之前,他会自动被执行
componentWillUpdate(){console.log('4')} 组件被更新之前,它会自动执行,但是他在shouldComponentUpdate之后,如果shouldComponentUpdate返回true它才执行,如果返回false就不会执行了
componentDidUpdate(){console.log('5')} 组件更新完成之后,他会被执行
componentWillReceiveProps(){console.log('child 6')} 一个组件要从父组件接受参数,只要父组件的render函数被重新执行了(第二次),子组件的这个生命周期函数就会被执行
componentWillUnmount(){console.log('child 7')} 当这个组件即将被从页面中剔除的时候,会被执行
网友评论