- 初次挂载:
getDefaultProps
、getInitialState
、componentWillMount
、render
、componentDidMount
- 卸载:
componentWillUnmount
- 重新挂载:
getInitialState
、componentWillMount
、render
、componentDidMount
- 组件更新:
componentWillReceiveProps
、shouldCompnentUpdate
、componentWillUpdate
、componentDidUpdate
为什么重新挂载的时候没有getDefaultProps
,因为React的生命周期主要通过3个阶段进行管理:MOUNTING,RECEIVE_PROPS和UNMOUNTING,3个阶段分别对应3个方法:mountComponent,updateComponent和ummountComponent;其中mountComponent负责管理生命周期中的getInitialState
、componentWillMount
、render
、componentDidMount
,由于getDefaultProps
是通过构造函数进行管理,也是整个生命周期中最先开始执行的,而mountComponent无法调用到getDefaultProps
,所以为什么getDefaultProps
只执行一次的原因。