思路1:每隔 1 秒种减 1 ,直到减到 0 为止。可以写成公用方法。亲测有效。
countDown(){
const TIME_COUNT = 60;
if (!this.timer) {
this.count = TIME_COUNT;
this.codeShow = false;
this.timer = setInterval(() => {
if (this.count > 0 && this.count <= TIME_COUNT) {
this.count--;
} else {
this.codeShow = true;
this.identifyText = "重新发送"
clearInterval(this.timer);
this.query.smsCode = ""
this.timer = null;
}
}
}
}