React 生命週期函式

2021-09-26 19:16:07 字數 1122 閱讀 5599

在某一時段會自動執行的函式

initialization初始化

constructo()中完成

mounting 元件第一次掛載到頁面的流程

componentwillmount :render之前    組建即將被掛載到頁面上時執行

componentdidmount :render之後     元件掛載後執行

updation 元件更新

shouldcomponentupdate  :給出乙個布林值判斷是否更新元件

componentwillupdate :確定更新元件,render前執行

componentdidupdate :元件更新後,render後執行

componentwillreceiveprops:一般只有子元件會執行,但是在子元件還沒掛載時不執行

componentwillunmount 元件除去掛載後執行

用處

shouldcomponentupdate(nextprops, nextstate) 

else

}

import axios from 'axios'

componentdidmount())

.catch(()=>)

console.log('todolist:componentdidmount')

}

React生命週期函式

說來慚愧,準大四計算機專業學生黨第一次寫技術部落格。以前學東西沒有記錄的習慣總是容易忘記。最近在看老師的教程學習react框架,想寫點東西記錄一下學習的過程。若寫的不好,各位大佬見諒了,歡迎指正。什麼是生命週期函式?生命週期函式就是元件某一時刻會自動執行的函式。initialzation 初始化 m...

React 生命週期函式

initialization 初始化 mounting 掛載 updation 更新 unmounting setup componentwillmount props states componentwillunmont 當這個元件即將被從頁面中移除的時候,會被執行 props render co...

react生命週期函式

生命週期函式 某一時刻元件會自動呼叫執行的函式 render也是 initialization 初始化 constructor裡 mounting 掛載 componentwillmount 接下來render 生命週期函式的使用場景 不可缺少的乙個生命週期函式是render 效能優化 減少無謂的渲...