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
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!