Vue父子组件生命周期执行顺序

vue2 中 执行顺序 :
beforeCreate => created => beforeMount => mounted => beforeUpdate => updated => beforeDestroy => destroyed
vue3 中 执行顺序 setup => onBeforeMount => onMounted => onBeforeUpdate => onUpdated => onBeforeUnmount => onUnmounted
对应关系
vue2 -> vue3

beforeCreate -> setup
created -> setup
beforeMount -> onBeforeMount
mounted -> onMounted
beforeUpdate -> onBeforeUpdate
updated -> onUpdated
beforeDestroy -> onBeforeUnmount
destroyed -> onUnmounted

父子组件执行顺序

挂载阶段

执行顺序为:
父beforeCreate => 父created => 父beforeMount => 子beforeCreate => 子created => 子beforeMount => 子mounted => 父mounted

更新阶段

执行顺序为:
父beforeUpdate => 子beforeUpdate => 子updated => 父updated

销毁阶段

执行顺序为:
父beforeDestroy => 子beforeDestroy => 子destroyed => 父destroyed

规律就是:父组件先开始执行,然后等到子组件执行完,父组件收尾。

你可能感兴趣的:(Vue父子组件生命周期执行顺序)