要达到的效果,注销组建 或者页面跳转 关掉计时器
第一
1、data里定义一个变量
data() {
return {
setTimeOutObj:null,
}
},
2、mounted(){}里
var a=1;
m.setTimeOutObj=setInterval(()=>{
a+=1
console.log(a)
},2000)
3、钩子beforeDestroy跟 methods和 mounted平级的!!!
//页面销毁后调用
beforeDestroy(){
let m=this;
clearInterval(m.setTimeOutObj);
},
4、我的 群153181864 前端交流群 ,绝对原创,转载请附上 本微博链接。