React 學習筆記 (六)(生命週期)

2021-08-31 01:15:47 字數 1258 閱讀 9547

元件載入時觸發的函式

constructor —> componentwillmount —> render —> componentdidmount

import react,  from 'react';

class lifecycle extends component ;

}// 資料將要掛載

componentwillmount()

// 資料渲染

render()

// 資料掛載完成

元件更新時觸發的函式

shouldcomponentupdate —> componentwillupdate —> render —> componentdidupdate

import react,  from 'react';

class lifecycle extends component ;

}// 是否要更新資料 返回true會更新資料 返回false不會更新資料

//nextprops 父子元件傳值時的資料 nextstate改變後的資料

shouldcomponentupdate(nextprops,nextstate)

// 資料將要更新

componentwillupdate()

getmsg=()=>)

}// 資料渲染

render()

// 資料更新完成

componentwillreceiveprops:在父元件裡面改變props傳值時觸發

componentwillreceiveprops()
componentwillunmount:元件銷毀時觸發的函式 銷毀哪個寫在哪個元件裡
componentwillunmount()

React學習筆記2 生命週期

生命週期函式指在某乙個時刻元件會自動呼叫執行的函式,react的生命週期函式主要有 父元件 在元件即將被掛載到頁面的時刻自動執行,掛載完畢不再執行 componentwillmount render 元件被掛載到頁面之後,自動被執行,掛載完畢不再執行 componentdidmount 元件被更新之...

React學習筆記2 生命週期

生命週期函式指在某乙個時刻元件會自動呼叫執行的函式,react的生命週期函式主要有 父元件 在元件即將被掛載到頁面的時刻自動執行,掛載完畢不再執行 componentwillmount render 元件被掛載到頁面之後,自動被執行,掛載完畢不再執行 componentdidmount 元件被更新之...

React學習筆記2 生命週期

生命週期函式指在某乙個時刻元件會自動呼叫執行的函式,react的生命週期函式主要有 父元件 在元件即將被掛載到頁面的時刻自動執行,掛載完畢不再執行 componentwillmount render 元件被掛載到頁面之後,自動被執行,掛載完畢不再執行 componentdidmount 元件被更新之...