vue中定时器设置和关闭页面时关闭定时器

methods中

setTime() //设置定时器
{
this.clearTimeSet=setInterval(() => {
this.webSocketClientOnopen();
}, 1000);
},

clearTime() //清除定时器
{
clearInterval(this.clearTimeSet);
}

mounted 
mounted : function () //页面加载完毕就开始加载定时器
{
this.setTime();
}

beforeDestroy() { //页面关闭时清除定时器
  clearInterval(this.clearTimeSet);
},
 
posted @ 2019-04-10 15:03  笨笨白  阅读(10194)  评论(0编辑  收藏  举报