activated:路由组件被激活时触发
deactivated:路由组件失活时触发
当 使用了 <keep-alive> </keep-alive>之后跳转到其他组件时,之前的组件不会被销毁 这时配置在beforeDestroy()中的方法就不会生效可能会产生资源浪费达不到想要的效果
例如
mounted(){this.timmer = setInterval(()=>{console.log('hello word')})
},
beforeDestroy(){console.log("要销毁了")clearInterval(this,timer)
},
若这个组件被 <keep-alive> </keep-alive>包裹则跳走时并不会触发 beforeDestroy ,定时就不会被关闭
activated(){this.timmer = setInterval(()=>{console.log('激活啦')})
},
deactivated(){console.log("要失活了")clearInterval(this,timer)
},
这样就可关闭定时器了
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态