vue3和vue2生命週期的對比

vue3和vue2生命週期的對比
vue

Vue3 的生命週期比較多。ide

  1. setup() :開始建立組件以前,在beforeCreate和created以前執行。建立的是data和method
  2. onBeforeMount() : 組件掛載到節點上以前執行的函數。
  3. onMounted() : 組件掛載完成後執行的函數。
  4. onBeforeUpdate(): 組件更新以前執行的函數。
  5. onUpdated(): 組件更新完成以後執行的函數。
  6. onBeforeUnmount(): 組件卸載以前執行的函數。
  7. onUnmounted(): 組件卸載完成後執行的函數。
  8. onActivated(): 被包含在
  9. onDeactivated(): 好比從 A 組件,切換到 B 組件,A 組件消失時執行。
  10. onErrorCaptured(): 當捕獲一個來自子孫組件的異常時激活鉤子函數(之後用到再講,很差展示)。

注:使用<keep-alive> 組件會將數據保留在內存中,好比咱們不想每次看到一個頁面都從新加載數據,就能夠使用函數

Vue2--------------vue3
beforeCreate  -> setup()
created       -> setup()
beforeMount   -> onBeforeMount
mounted       -> onMounted
beforeUpdate  -> onBeforeUpdate
updated       -> onUpdated
beforeDestroy -> onBeforeUnmount
destroyed     -> onUnmounted
activated     -> onActivated
deactivated   -> onDeactivated
errorCaptured -> onErrorCaptured
相關文章
相關標籤/搜索