vue有哪些声明周期
beforeCreate(){}
created(){}
beforeMounte(){}
mounted(){}
beforeUpdate(){}
updated(){}
beforeDestroy(){}
destroyed(){}
vue页面初始化都执行哪些声明周期
beforeCreate(){},
created(){},
beforeMounte(){},
mounted(){},
vue在哪个生命周期中有 el,data
beforeCreate中没有$el,也没有$data
mounted中有$el
created、beforeMounted、mounted:$data
如果加入keep-alive会多两个生命周期
activated:进入
deactivated:销毁
如果加入了缓存组件keep-alive,第一次会执行哪些生命周期
beforeCreate(){}
created(){}
befroeMounte(){}
mounted(){}
activated
如果加入了keep-alive,第二次/第N次进入组件会执行哪些生命周期
只执行一个生命周期:activated(){},
因为已经被缓存了,所以第二次或第N次的时候,只会执行activated
总结:
面试官问:你能说一下vue生命周期吗?
vue自带的系统生命周期有8个
beforeCreate、created、beforeMounte、mounted、beforeauapdate、updated、beforeDestroy、destroyed
第一次执行组件时,会执行前面4个生命周期
如果假如keep-alive就变成了10个生命周期,activated和deactivated
如果加入了keep-alive的话,第一次执行生命周期,会执行5个:beforeCreate、created、beforeMounte、mounted、activated
第二次或第N次执行则会执行1个activated