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
相关文章
相关标签/搜索