与 2.x 版本生命周期相对应的组合式 API
beforeCreate -> 使用 setup()
created -> 使用 setup()
beforeMount -> onBeforeMount
mounted -> onMounted
beforeUpdate -> onBeforeUpdate
updated -> onUpdated
beforeDestroy -> onBeforeUnmount
destroyed -> onUnmounted
errorCaptured -> onErrorCaptured
使用
import {onBeforeMount,onMounted } from 'vue'//在组件被挂载之前调用onBeforeMount(()=>{console.log('组件被挂载之前')})//在组件被挂载之后调用onMounted(() => {console.log('在组件被挂载之后')});