生命週期
差別
名稱
option vue2 | option vue3 | composition vue3(自己引入) |
beforeCreate | beforeCreate | setup() |
created | created | setup() |
beforeMount | beforeMount | onBeforeMount(()=>{}) |
mounted | mounted | onMounted(()=>{}) |
beforeUpdate | beforeUpdate | onBeforeUpdate(()=>{}) |
updated | updated | onUpdated(()=>{}) |
beforeDestroy | beforeUnmount | onBeforeUnmount(()=>{}) |
destroyed | unmounted | onUnmounted(()=>{}) |
vue2 流程
new Vue → beforeCreate → created → 判斷是否有el還是$mount → …
vue3 流程
Vue.createApp → mount → 再去走生命週期 → ….
注意
composition的生命週期觸發優先級會快於option生命週期觸發(不過通常不會一起用)