与vue2生命周期钩子对比
beforeCreate -> setup() 开始创建组件之前,创建的是data和method
created -> setup()
beforeMount -> onBeforeMount 组件挂载到节点上之前执行的函数。
mounted -> onMounted 组件挂载完成后执行的函数
beforeUpdate -> onBeforeUpdate 组件更新之前执行的函数。
updated -> onUpdated 组件更新完成之后执行的函数。
beforeDestroy -> onBeforeUnmount 组件挂载到节点上之前执行的函数。
destroyed -> onUnmounted 组件卸载之前执行的函数。
与vue2生命周期的区别
- beforeDestroy 改为 onBeforeUnmount,destroyed 改为 unmounted;
- 在使用组合式 API生命周期之前要先引入;
- 如果组合式 API生命周期和Options API 生命周期同时存在,都会执行,但是先执行组合式 API生命周期。