vue的父组件及子组件的执行顺序

顺序:

父beforeCreated -> 父created-> 父beforeMounted->子beforeCreated ->子created->子beforeMounted->子mounted->父mounted->父beforeUpdata->子beforeUpdata->子updata->父updata->父beforeDestroyed->子beforeDestroyed->子destroyed->父destroyed


常用方式:

希望父组件加载完成在加载子组件:

在子组件上添加v-if=‘isShow’ isShow默认值是false,在父组件的mounted中将isShow变成true,执行顺序变成如下:

父beforeCreated -> 父created-> 父beforeMounted->父mounted->父beforeUpdata->子beforeCreated ->子created->子beforeMounted->子mounted->子beforeUpdata->子updata->父updata->父beforeDestroyed->子beforeDestroyed->子destroyed->父destroyed


***在mounted中才可以触发updated,

你可能感兴趣的:(vue的父组件及子组件的执行顺序)