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

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

渲染过程:父组件挂载完成一定是等子组件都挂载完成后,才算是父组件挂载完,所以父组件的mounted在子组件mouted之后。父beforeCreate -> 父created -> 父beforeMount -> 子beforeCreate -> 子created -> 子beforeMount -> 子mounted -> 父mounted

子组件更新过程:

影响到父组件: 父beforeUpdate -> 子beforeUpdate->子updated -> 父updated

不影响父组件: 子beforeUpdate -> 子updated

父组件更新过程:

影响到子组件: 父beforeUpdate -> 子beforeUpdate->子updated -> 父updated

不影响子组件: 父beforeUpdate -> 父updated

销毁过程:父beforeDestroy -> 子beforeDestroy -> 子destroyed -> 父destroyed

看起来很多好像很难记忆,其实只要理解了,不管是哪种情况,都一定是父组件等待子组件完成后,才会执行自己对应完成的钩子,就可以很容易记住

猜你喜欢

转载自www.cnblogs.com/wtsx-2019/p/12411987.html
今日推荐