ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

vue3生命周期

2026/9/27 22:12:59 拓冰建站 浏览量
vue3生命周期

在 Vue 3 中,生命周期方法的名称有所改变。下面是 Vue 3 中的生命周期方法:

  1. beforeCreate -> setup() 前,初始化 props、data
  2. created -> setup() 内部,初始化后创建
  3. beforeMount -> onBeforeMount 组件挂载之前
  4. mounted -> onMounted 组件挂载之后
  5. beforeUpdate -> onBeforeUpdate 组件更新之前
  6. updated -> onUpdated 组件更新之后
  7. beforeUnmount -> onBeforeUnmount 组件卸载之前
  8. unmounted -> onUnmounted 组件卸载之后
  9. errorCaptured -> onErrorCaptured 捕获组件内部错误

除了名称变化外,Vue 3 也引入了新的生命周期 API,如:

  1. onRenderTracked 在依赖项被追踪时调用
  2. onRenderTriggered 在组件重新渲染时调用

import { onMounted  } from 'vue'

onMounted ( () => {})