ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

vue3生命周期

vue3生命周期

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

  1. beforeCreate -> setup() 前,初始化 propsdata
  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 ( () => {})

返回列表