Initialization 初始化
Mounting:挂载
Updation:更新
Unmounting:销毁
constructor构造函数,它是ES6的基本语法。虽然它和生命周期函数的性质一样,但不能认为是生命周期函数。
- Mounting
componentWillMount : 在组件即将被挂载到页面的时刻执行。
render : 页面state或props发生变化时执行。
componentDidMount : 组件挂载完成时被执行。
componentWillMount和componentDidMount这两个生命周期函数,只在页面刷新时执行一次,而render函数是只要有state和props变化就会执行。
- Updation
1-shouldComponentUpdate---组件发生改变前执行
2-componentWillUpdate---组件更新前,shouldComponentUpdate函数之后执行
3-render----开始挂载渲染
4-componentDidUpdate----组件更新之后执行
shouldComponentUpdate return true componentWillUpdate 才会执行
componentWillReceiveProps
子组件接收到父组件传递过来的参数,父组件render函数重新被执行,这个生命周期就会被执行。
也就是说这个组件第一次存在于Dom中,函数是不会被执行的;
如果已经存在于Dom中,函数才会被执行。
- unMounting
componentWillUnmount
这个函数时组件从页面中删除的时候执行
利用生命周期函数优化性能。
网友评论