當組件在客戶端第一次創(chuàng)建時虫蝶,依次調(diào)用以下方法
- getDefaultProps
- getInitialState
- componentWillMount
- render
- componentDidMount
當組件在服務(wù)端第一次創(chuàng)建時罢荡,依次調(diào)用以下方法
- getDefaultProps
- getInitialState
- componentWillMount
- render
componentDidMount不會在服務(wù)端被渲染的時候調(diào)用
當狀態(tài)改變時毅贮,依次調(diào)用以下方法
- componentWillReceiveProps
- shouldComponentUpdate
- componentWillUpdate
- render
- componentDidUpdate
銷毀時調(diào)用componentWillUnmount
測試發(fā)現(xiàn)當狀態(tài)改變時,componentWillUpdate 里面的state還是之前的state,若想根據(jù)state的值進行頁面的跳轉(zhuǎn)或其他操作录择,應(yīng)該在componentDidUpdate 中進行判斷,并進行邏輯處理。