react手記(componentWillMount,componentDidMount等)


生命周期
componentWillMount 組件出現前 就是dom還沒有渲染到html文檔里面
componentDidMount 組件渲染完成 已經出現在dom文檔里
可以再各個周期實現特定的操作

 

生命周期的方法有:

componentWillMount 在渲染前調用,在客戶端也在服務端。

componentDidMount : 在第一次渲染后調用,只在客戶端。之后組件已經生成了對應的DOM結構,可以通過this.getDOMNode()來進行訪問。 如果你想和其他JavaScript框架一起使用,可以在這個方法中調用setTimeout, setInterval或者發送AJAX請求等操作(防止異部操作阻塞UI)。

componentWillReceiveProps 在組件接收到一個新的 prop (更新后)時被調用。這個方法在初始化render時不會被調用。

shouldComponentUpdate 返回一個布爾值。在組件接收到新的props或者state時被調用。在初始化時或者使用forceUpdate時不被調用。 可以在你確認不需要更新組件時使用。

componentWillUpdate在組件接收到新的props或者state但還沒有render時被調用。在初始化時不會被調用。

componentDidUpdate 在組件完成更新后立即調用。在初始化時不會被調用。

componentWillUnmount在組件從 DOM 中移除的時候立刻被調用。

 

React 組件生命周期:http://www.runoob.com/react/react-component-life-cycle.html

React.Component:https://reactjs.org/docs/react-component.html#lifecycle-methods

構成與繼承:https://reactjs.org/docs/composition-vs-inheritance.html

React組件生命周期過程說明:http://react-china.org/t/react/1740


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM