VUE3.X入门必看
element-plus入门必看
Vue3 的生命周期(Plus)
1. setup() :开始创建组件之前,在 beforeCreate 和 created 之前执行。创建的是 data 和 method
2. onBeforeMount() : 组件挂载到节点上之前执行的函数。
3. onMounted() : 组件挂载完成后执行的函数。
4. onBeforeUpdate(): 组件更新之前执行的函数。
5. onUpdated(): 组件更新完成之后执行的函数。
6. onBeforeUnmount(): 组件卸载之前执行的函数(仅在未配置缓存页面中生效)。
7. onUnmounted(): 组件卸载完成后执行的函数(仅在未配置缓存页面中生效)。
8. onActivated(): 被包含在<keep-alive>中的组件,会多出两个生命周期钩子函数。被激活时执行。(仅在配置了缓存的页面中生效)。
9. onDeactivated(): 被包含在<keep-alive>中的组件,会多出两个生命周期钩子函数。比如从 A 组件,切换到 B 组件,A 组件消失时执行(仅在配置了缓存的页面中生效)。
10. onErrorCaptured(): 当捕获一个来自子孙组件的异常时激活钩子函数(不常用)。
Vue2.x 和 Vue3.x 生命周期对比
Vue2--------------vue3
1. beforeCreate -> setup()
2. created -> setup()
3. beforeMount -> onBeforeMount
4. mounted -> onMounted
5. beforeUpdate -> onBeforeUpdate
6. updated -> onUpdated
7. beforeDestroy -> onBeforeUnmount
8. destroyed -> onUnmounted
9. activated -> onActivated
10. deactivated -> onDeactivated
11. errorCaptured -> onErrorCaptured
万能独立守卫
beforeRouteLeave (to, from, next) {
// 导航离开该组件的对应路由时去做你想做的事。
next()
}
发表评论 取消回复