目录
  • 周期对比
  • 用法
  • 总结

周期对比

vue2 vue3
beforeCreate setup
created setup
beforeMount onBeforeMount
mounted onMounted
beforeUpdate onBeforeUpdate
updated onUpdated
activeted onActiveted
deactiveted onDeactiveted
beforeDestory onBeforeUnmount
destoryed onUnmounted

用法

vue2 中的生命周期与 data / methods 同级别以函数方式使用,比如 created() {}

data() {
    return {}
},
created() {
    ...
}

vue3 中的生命周期 setup 在最外层,不需要按需加载,其他的生命周期得按需加载才能使用

import { omMounted } from 'vue'
setup() {
    onMounted(() => { ... })
}

总结

本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注的更多内容!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。