React之生命週期函式
阿新 • • 發佈:2019-02-05
一:Mounting
1:componentWillMount():在元件即將掛載在頁面的時刻自動執行
2:render():
3:componentDidMount():在元件掛載在頁面後的時刻自動執行
二:Updation
1:componentWillReceiveProps():需要滿足三個條件才會執行
一個元件要從父元件接受引數
如果這個元件第一次存在父元件中,不會執行如果這個元件已經存在父元件中,才會執行
2:shouldComponentUpdate():元件被更新之前,會自動執行,返回一個布林值,
表示元件是否應該被更新
如果return true;執行元件更新函式componentWillUpdate()
3:componentWillUpdate():元件被更新之前,會自動執行,
但是它在shouldComponentUpdate()返回true之後執行
如果shouldComponentUpdate()返回的是false,則不執行
4:render():重新渲染虛擬DOM
5:componentDidUpdate():元件被更新之後,會自動執行
三:Unmounting
1:componentWillUnmount():元件解除安裝之後執行