vue中倒计时假清除

时间:2021-02-01 11:53:09   收藏:0   阅读:0

// 获取验证码
getCodes(){
const TIME_COUNT = 60;
if (!this.timer) {
this.count = TIME_COUNT;
this.show = false;
this.getcode()
this.timer = setInterval(() => {
if (this.count > 0 && this.count <= TIME_COUNT) {
this.count--;
} else {
this.show = true;
clearInterval(this.timer);

}
}, 1000)
}
},

如果只使用clearInterval(this.timer);关闭定时器的话

在手机上该定时器其实是没有关闭的状态

需要在将定义定时器的属性设置为null

this.timer = null;

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!