vue中倒计时假清除
// 获取验证码
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;