简单实现vue验证码60秒倒计时功能
<div v-show="show" @click="getCode">获取验证码</div>
<div-show="!show" class="count">{{count}} s</div>
data(){
return {
show: true,
count: '',
timer: null,
}
},
methods:{
getCode(){
const intime = 60;
if (!this.timer) {
this.count = intime;
this.show = false;
this.timer = setInterval(() => {
if (this.count > 0 && this.count <= intime) {
this.count--;
} else {
this.show = true;
clearInterval(this.timer);
this.timer = null;
}
}, 1000)
}
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-44652.html