, 官方不推荐我们这么做, 也不建议我们在constructor中, 有以下两点原因
会阻碍组件的实例化,阻碍组件的渲染
如果用setState,在componentWillMount里面触发setState...,具体可以看这个issue
在16.3之后react开始异步渲染,在异步渲染模式下,使用componentWillMount会被多次调用,并且存在内存泄漏等问题
关于在componentWillMount...比componentDidMount请求早,具体应该是componentWillMount会立即执行,执行完之后会立即进行render
在componentDidMount 被调用后,componentWillUnmount...一定随后被调用
4.componentDidMount
这个方法在组件被mount后被立即调用....相信在 React 正式开启异步渲染模式之后, 许多常用组件的性能将很有可能迎来一次整体的提升。