0
点赞
收藏
分享

微信扫一扫

vue 3.0 中生命周期中钩子函数

晴儿成长记 2022-03-13 阅读 89
vue 3.0中可以继续使用 vue2.0 中的生命周期钩子, 但是有两个被更名:
beforeDestroy 更名为 beforeUnmount;
destroryed 更名为 unmounted;

vue 3.0 也提供了COmposition API 形式的生命周期钩子, 与vue2.0钩子对应关系如下:
1: beforeCreate ===> setup() 函数;
2: created ===> setup() 函数;
3: beforeMount ===> onBeforeMount
4: mounted ===> onMounted;
5: boforeUpdate ====> onBeofreUpdate;
6: updated ===> onUpdated
7: beforeUnmount ===> onBeforeUnmount
8: unMounted ===> onUnmounted;

2: 自定义hook 钩子函数:
什么是hook? 本质就是一个函数, 既是把setup 函数中使用的Composition API 进行了封装。
类似与vue2.0 中的mixin;
自定义hook 的优势: 复用代码, 让setup 中逻辑更清楚易懂。
类似于 vue2.0 中的minix 混入
举报

相关推荐

0 条评论