@vue定时器和关闭定时器
vue定时器和关闭定时器
mounted() {//页面加载完成后执行方法(启动定时器)
clearInterval(this.timer)
this.setTimer()
},
//distroyed: function () {//页面关闭后关闭定时器(并没用)
// console.log('distroyed')
// clearInterval(this.timer)
//},
beforeDestroy() {//页面关闭前关闭定时器 (这个才有用)
clearInterval(this.timer)
},
methods: {
setTimer: function () {
this.timer = setInterval( () => {
console.log("定时执行方法");
}, 3000);
},
}
vue生命周期 学习
https://segmentfault.com/a/1190000008010666
版权声明:本文为ZhangYuan2HH原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。