亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

生命周期問題

父組件掛載三次子組件:生命周期函數執行流程真實的是這樣的(對比標箭頭的地方)

? ? super constructor

? ? super componentWillMount

? ? super render


? ? ? ? ->child componentWillMount

? ? ? ? ->child render

? ? ? ? ->child componentWillMount

? ? ? ? ->child render

? ? ? ? ->child componentWillMount

? ? ? ? ->child render

? ? ? ? ->child componentDidMount

? ? ? ? ->child componentDidMount

? ? ? ? ->child componentDidMount


? ? super componentDidMount


為什么不是這樣的?

? ? super constructor

? ? super componentWillMount

? ? super render


? ? ? ? ->child componentWillMount

? ? ? ? ->child render

? ? ? ? ->child componentDidMount

? ? ? ? ->child componentWillMount

? ? ? ? ->child render

? ? ? ? ->child componentWillMount

? ? ? ? ->child render

? ? ? ? ->child componentDidMount


? ? super componentDidMount


正在回答

1 回答

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

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

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

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

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

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

  • componentWillUnmount在組件從 DOM 中移除之前立刻被調用。


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
React16.4 快速上手
  • 參與學習       40300    人
  • 解答問題       137    個

結合實例帶你快速入門React16基礎語法,并完成Todolist功能開發。

進入課程

生命周期問題

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號