生命周期
各个阶段生命周期钩子函数
一、组件嵌套时执行顺序
嵌套情况:祖组件 => 父组件 => 子组件
1.启动:
grand father beforeCreate
grand father created
grand father beforeMount
father beforeCreate
father created
father beforeMount
son beforeCreate
son created
son beforeMount
son mounted
father mounted
grand father mounted
2.卸载父组件:
grand father beforeUpdate
father beforeUnmount
son beforeUnmount
son unmounted
father unmounted
grand father updated
3.挂载父组件
grand father beforeUpdate
father beforeCreate
father created
father beforeMount
son beforeCreate
son created
son beforeMount
son mounted
father mounted
grand father updated
结论:beforeMount之后开始示例化子组件
二、<KeepAlive>的情况
1.初始化
2.切走
3.切回
结论:
挂载时,mounted后再activated
切走的时候先加载新组件,再缓存旧组件:不执行unmount相关钩子,而是deactivated
切回的时候不再执行create和mount相关钩子,而是activated
所以keep-alive是对组件实例的缓存,无需重新渲染
Last updated