Skip to content

生命周期

  • 按需导入到组件中,且只能setup() 函数中使用
vue 2.xvue 3
beforeCreatesetup
createdsetup
beforeMountonBeforeMount
mountedonMounted
beforeUpdateonBeforeUpdate
updatedonUpdated
beforeDestroyonBeforeUnmount
destroyedonUnmounted
errorCapturedonErrorCaptured
renderTriggeredonRenderTriggered
js
import { onMounted } from 'vue'

setup(){
    onMounted(() => {
      console.log('mounted')
    })
}
  • onActivated – 被 keep-alive 缓存的组件激活时调用
  • onDeactivated – 被 keep-alive 缓存的组件停用时调用