1.React的生命周期:
生命周期分为4部分:
(1)Initialization:初始化化阶段
constructor()
(2)Mounting:挂载阶段
Mounting阶段又可以分为3个小阶段:
(1)componentWillMount : 在组件即将被挂载到页面的时刻执行
(2)render : 页面state或props发生变化时执行
(3)componentDidMount : 组件挂载完成时被执行
(3)Updation:更新阶段
(1)shouldComponentUpdate:函数会在组件更新之前,返回true或者false
(2)componentWillUpdate:在组件更新之前,在shouldComponentUpdate之后执行,如果shouldComponentUpdate返回false,该函数不会执行
(3)render:开始挂载渲染
(4)componentDidUpdate:在组件更新之后执行
(5)componentWillReceiveProps:子组件接收到父组件传递过来的参数,父组件render函数重新被执行,这个生命周期就会被执行。
(4)Unmounting:销毁阶段
(1)componentWillUnmount:组件从页面中删除的时候执行