1.vue2.x生命周期:
2.vue3.0生命周期:
- Vue3.0中可以继续使用Vue2.x中的生命周期钩子,但有两个被更名:
-
beforeDestroy改名为beforeUnmount -
destroyed改名为unmounted
- Vue3.0也提供了Composition API 形式的生命周期钩子,与Vue2.x中钩子对应关系如下:
-
beforeCreate ==>setup()
-
created ==>setup()
-
beforeMount ==>onBeforeMount
-
mounted ==>onMounted
-
beforeUpdate ==>onBeforeUpdated
-
updated ==>onUpdated
-
beforeUnmount ==>onBeforeUnMount
-
unmounted ==>onUnMounted