vue离开页面销毁定时器
vue 是单页面应用,路由切换后,定时器并不会自动关闭,需要手动清除,当页面被销毁时,清除定时器即可。data: {return {timer: null}},created() {this.timer = setInterval(....);},beforeDestroy() {if(this.timer) { //如果定时器还在运行 或者直接关闭,不用判断clearInterval(this.
·
vue 是单页面应用,路由切换后,定时器并不会自动关闭,需要手动清除,当页面被销毁时,清除定时器即可。
data: {
return {
timer: null
}
},
created() {
this.timer = setInterval(....);
},
beforeDestroy() {
if(this.timer) { //如果定时器还在运行 或者直接关闭,不用判断
clearInterval(this.timer); //关闭
}
}
更多推荐
已为社区贡献33条内容
所有评论(0)