vue生命周期

103 阅读1分钟

vue2生命周期

activated, deactivated 是组件keep-alive时独有的钩子
beforeCreate created beforeMount mounted beforeUpdate updated activated deactivated beforeDestroy destroyed errorCaptured

vue3生命周期

除了beforeCreate和created(被setup方法本身代替),共有9个Options API生命周期相对应的方法可以在setup中使用。

onBeforeMount——挂载开始前调用 onMount——挂载后调用 onBeforeUpdate——当响应数据改变,且重新渲染前调用 onUpdated——重新渲染后调用 onBeforeUnmount——Vue实例销毁前调用 onUnmounted——实例销毁后调用 onActivated——当keep-alive组件被激活时调用 onDeactivated——当keep-alive组件取消激活时调用 onErrorCaptured——从子组件中捕获错误时调用

父子组件生命周期

挂载

father beforeCreate
father created
father beforeMount
son beforeCreate
son created
son beforeMount
son mounted
father mounted

更新

father beforeUpdate
son beforeUpdate
son updated
father updated

销毁

father beforeDistroy
son beforeDistroy
son distroyed
father distroyed

参考