在服务端渲染时 componentDidMount 是不会被调用的,只会调用componentWillMount.
2.在componentWillMount中, 我们一般会用来异步获取数据, 但是在新版生命周期中...不会重新渲染
3.官方推荐我们使用componentDidMount, 选择在componentDidMount有几个原因:
componentDidMount指的是第一次插入dom完毕,无论在同步和异步模式下都仅会触发一次...在目前16.3之前的react版本中 ,react是同步渲染的, 在componentWillMount中接口调用,有可能不会触发界面渲染,而在componentDidMount中渲染一定会触发界面渲染...一定会随后被调用到, 所以我们在componentDidMount里面注册的事件订阅都可以在这里取消掉, 而componentWillMount被调用并不能保证componentWillUnmount...一定随后被调用
4.componentDidMount
这个方法在组件被mount后被立即调用.