<div v-if="countdown" @click="getSMSCode">获取验证码</div>
<div v-else>{{count}}s</div>
data() {
return {
countdown: true,
count: "",
timer: null,
}
}
getSMSCode() {
if (datas.data.Rescode == "0000") {
this.countdown = !this.countdown;
const TIME_COUNT = 60;
if (!this.timer) {
this.count = TIME_COUNT;
this.countdown = false;
this.timer = setInterval(() => {
if (this.count > 0 && this.count <= TIME_COUNT){
this.count--;
} else {
this.countdown = true;
clearInterval(this.timer);
this.timer = null;
}
}, 1000);
}
}
},