vue 手机验证码倒计时
- data中 定义一个类型null 用于存放定时器
比如data (){ return { timer: null }}
- 接下来就是方法了
if (!this.timer) {
let CountDown = 60; // 倒计时
this.codeStatus = true; // 按钮禁用状态 ,自己定义下一
this.codeTimeout = CountDown;
this.timer = setInterval(() => {
if (this.codeTimeout > 0 && this.codeTimeout <= CountDown) {
this.codeTimeout--;
}else{
this.codeStatus = false;
clearInterval(this.timer);
this.timer = null;
}
}, 1000);
}