vue中定时器设置和关闭页面时关闭定时器
时间:2019-04-10 15:49:12
收藏:0
阅读:1396
methods中
setTime() //设置定时器
{
this.clearTimeSet=setInterval(() => {
this.webSocketClientOnopen();
}, 1000);
},
clearTime() //清除定时器
{
clearInterval(this.clearTimeSet);
}
mounted 中
mounted : function () //页面加载完毕就开始加载定时器
{
this.setTime();
}
beforeDestroy() { //页面关闭时清除定时器
clearInterval(this.clearTimeSet);
},
原文:https://www.cnblogs.com/benbenbai/p/10683495.html
评论(0)