React组件的生命周期
可分为三个状态:
Mounting: 已插入真实DOM
Updating: 正在被重新渲染
Unmounting: 已移出真实DOM
生命周期的方法:
componentWillMount 在渲染前调用,在客户端也在给服务端
componentDidMount 在第一次渲染后调用,只在客户端,可发送请求,调用定时器等
componentWillReceiveProps 在组件接收到一个新的prop时被调用,初始化render不会调用
shouldComponentUpdate 返回一个布尔值,在组件接收到新的props或state时被调用
componentWillUpdate 在组件接受到新的props或state但还没有render时被调用
componentDidUpdate 组件更新后立即调用
componentWillUnmount 组件从DOM中移除之前被立即调用

浙公网安备 33010602011771号