react常用生命周期
1、constructor
(1)通过给this.state赋值对象来初始化内部的state
(2)为事件绑定实例(this)
2、componentDidMount
(1)依赖于DOM的操作可在这里进行
(2)在此处发送网络请求(官方推荐)
(3)可在此处添加一些事件的订阅(在componentWillUnmount取消订阅)
3、componentDidUpdate
(1)当组件更新后,可在此处对DOM进行操作
(2)可获取props的变化前后值
4、componentWillUnmount
(1)在此方法中执行必要的清理操作,像:timer、网络请求、创建的事件订阅
浙公网安备 33010602011771号