timeDown: function () {
let time = 10;
this.sendCodeTxt = '还剩10秒';
this.timer = window.setInterval(()=>{
console.log(time);
if(time < 1){
this.sendCodeTxt = '发送验证码';
window.clearInterval(this.timer);
this.timer = null;
}else{
--time;
this.sendCodeTxt = '还剩'+time+'秒';
}
},1000);
},
vue 清除定时器,clearInterval
let time = 10
let intervalFunc = window.setInterval(() => {
time = time - 1
if (time < 1) {
window.clearInterval(intervalFunc)
}
}, 1000)