vue生命周期笔记之actived和deactived
使用场景:
页面有搜索区和列表区
需求:页面切换后搜索区的内容保存,列表区内容更新
原因:页面使用了keep-alive缓存,导致不走生命周期created\mounted,但会走activated,所以把列表接口放activated里,实现局部更新.
// keep-alive后,重新进入页面后不会走created和mounted,但会走activated
activated() {
// 请求列表接口
this.submitQuery();
},
actived和deactived区别:
actived进入页面类似created\mounted,deactived离开页面类似destory
updated
虚拟dom(页面)使用的值, 包括data和props传的值,父组件页面使用的值更新,子组件的updated也会进入,需要达到同样的效果官方推荐使用computed和watch
updated() {
// 勘误定位号
this.$nextTick(() => {
console.log(12321);
})
},