React生命周期
react生命周期分为三个阶段:
- 挂载(Mounting):已经插入真实DOM
- 更新(Updating):正在被重新渲染
- 卸载(Unmounting):已移出真实DOM
react生命周期函数:
1.componentWillMount :在渲染前调用,在客户端也在服务端。
2.componentDidMount : 在第一次渲染后调用,只在客户端。之后组件已经生成了对应的DOM结构,可以通过this.getDOMNode()来进行访问。 如果你想和其他JavaScript框架一起使用,可以在这个方法中调用setTimeout, setInterval或者发送AJAX请求等操作(防止异步操作阻塞UI)。
3.componentWillReceiveProps :在组件接收到一个新的 prop (更新后)时被调用。这个方法在初始化render时不会被调用。
4.shouldComponentUpdate :返回一个布尔值。在组件接收到新的props或者state时被调用。在初始化时或者使用forceUpdate时不被调用。可以在你确认不需要更新组件时使用。
5.componentWillUpdate:在组件接收到新的props或者state但还没有render时被调用。在初始化时不会被调用。
6.componentDidUpdate :在组件完成更新后立即调用。在初始化时不会被调用。
7.componentWillUnmount:在组件从 DOM 中移除之前立刻被调用。
本文地址:https://blog.csdn.net/biubiubiuXXD/article/details/107382746
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!
网友评论