react的生命周期
1.初始化过程constructor()
- 接收参数
- 只会触发一次!!
2.挂载过程(Mounting)
-
componentWillMount
在组件即将被挂载到页面的时刻自动执行。 -
render()
将组件挂载到页面。 -
componentDidMount
组件被挂载到页面之后立即执行
请求一般放在这里 -
componentWillReceiveProps
在组件接收到一个新的 prop(更新后)时被调用。这个方法在初始化render时不会被调用。 -
shouldComponentUpdate
返回一个布尔值。在组件接收到新的props或者state时被调用。在初始化时或者使用forceUpdate时不被调用。可以在你确认不需要更新组件时使用。 -
componentWillUpdate
在组件接收到新的props或者state但还没有render时被调用。在初始化时不会被调用。 -
componentDidUpdate
在组件完成更新后立即调用。在初始化时不会被调用。 -
componentWillUnmount
在组件从 DOM 中移除之前立刻被调用。