import { onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount, onUnmounted, onActivated, onDeactivated, onErrorCaptured } from 'vue'
export default { setup() { onBeforeMount(() => { // }) onMounted(() => { // }) onBeforeUpdate(() => { // }) onUpdated(() => { // }) onBeforeUnmount(() => { // ... }) onUnmounted(() => { // ... }) onActivated(() => { // ... }) onDeactivated(() => { // ... }) } }
vue2/vue3生命周期对比 beforeCreate -> use setup()//创建前 created (){} -> use setup()//创建后 beforeMount -> onBeforeMount//载入前 mounted(){} -> onMounted//载入后 beforeUpdate -> onBeforeUpdate//更新前 updated -> onUpdated//更新后 beforeDestroy -> onBeforeUnmount//销毁前 destroyed -> onUnmounted//销毁后 //下面两个是缓存组件 的生命周期 activated(){} -> onActivated//触发时机:keep-alive组件激活时调用; deactivated -> onDeactivated//触发时机:keep-alive组件停用时调用;