vue2 中 執(zhí)行順序 :
beforeCreate => created => beforeMount => mounted => beforeUpdate => updated => beforeDestroy => destroyed
vue3 中 執(zhí)行順序 setup => onBeforeMount => onMounted => onBeforeUpdate => onUpdated => onBeforeUnmount => onUnmounted
對應(yīng)關(guān)系
vue2 -> vue3
beforeCreate -> setup
created -> setup
beforeMount -> onBeforeMount
mounted -> onMounted
beforeUpdate -> onBeforeUpdate
updated -> onUpdated
beforeDestroy -> onBeforeUnmount
destroyed -> onUnmounted
父子組件執(zhí)行順序
掛載階段
執(zhí)行順序?yàn)椋?br> 父beforeCreate => 父created => 父beforeMount => 子beforeCreate => 子created => 子beforeMount => 子mounted => 父mounted
更新階段
執(zhí)行順序?yàn)椋?br> 父beforeUpdate => 子beforeUpdate => 子updated => 父updated
銷毀階段
執(zhí)行順序?yàn)椋?br> 父beforeDestroy => 子beforeDestroy => 子destroyed => 父destroyed
規(guī)律就是:父組件先開始執(zhí)行淘邻,然后等到子組件執(zhí)行完破停,父組件收尾。