Vue或者uniapp获取手机短信验证码
<button class=“verificationCode-right” @click=“getCode()” type=“default” :disabled="!show">
data里面定义
TIME_COUNT:120,//验证码倒计时60s
count:’’,
show:true,
methods里面定义*
// 验证码倒计时60s
getCode(){
if (!this.timer) {
this.count = this.TIME_COUNT;
this.show = false;
this.timer = setInterval(() => {
if (this.count > 0 && this.count <= this.TIME_COUNT) {
this.count--;
} else {
this.show = true;
clearInterval(this.timer);
this.timer = null;
}
}, 1000)
}
},