图示(Vue2为例):
对比:
vue2 | Description | vue3 | Description |
---|---|---|---|
beforeCreate | 组件实例刚被创建,组件属性计算之前,如data属性等 | setup | 开始创建组件之前,在 beforeCreate 和 created 之前执行。创建的是 data 和 method |
created | 组件实例刚被创建,属性已绑定,但DOM还没生成,$el属性还不存在 | ||
beforeMount | 模块编译/挂载之前 | onBeforeMount | 模块编译/挂载之前 |
mounted | 模块编译/挂载之后 | onMounted | 模块编译/挂载之后 |
beforeUpdate | 组件更新之前 | onBeforeUpdate | 组件更新之前 |
updated | 组件更新之后 | onUpdated | 组件更新之后 |
beforeDestroy | 组件销毁/卸载之前 | onBeforeUnmount | 组件销毁/卸载之前 |
destroyed | 组件销毁/卸载后 | onUnmounted | 组件销毁/卸载后 |
补充:
vue2 | vue3 | Description |
---|---|---|
activated | onActivated | 组件被激活时(手动) |
deactivated | onDeactivated | 组件被移除时(手动) |
errorCaptured | onErrorCaptured | 捕获一个来自子孙组件的错误时被调用(被动) |