如果在created请求了某个定时的函数时,跳转页面的时候要在beforeDestroy和destroyed()清除定时器。
created() {
this.timing()
},
methods:{
timing() {//定时函数模拟
this.clearTime();
this.timer = setInterval(() => {
console.log("6666")
}, 3000);
},
}
beforeDestroy() {//生命周期销毁前清除定时器
this.timer && clearInterval(this.timer);
},
destroyed() {//生命周期销毁后清除定时器
this.timer && clearInterval(this.timer);
},