其他分享
首页 > 其他分享> > Vue验证码倒计时按钮

Vue验证码倒计时按钮

作者:互联网

按钮:
<button class="yzm" @click="countDown">{{content}}</button>

事件:

countDown() {
if (!this.canClick) return //改动的是这两行代码
this.canClick = false
this.content = this.totalTime + 's后重新发送'
let clock = window.setInterval(() => {
this.totalTime--
this.content = this.totalTime + 's后重新发送'
if (this.totalTime < 0) {
window.clearInterval(clock)
this.content = '重新发送验证码'
this.totalTime = 60
this.canClick = true //这里重新开启
}
},1000)
},

标签:totalTime,content,Vue,clock,验证码,canClick,发送,倒计时,window
来源: https://www.cnblogs.com/PoisonousMushrooms/p/11977859.html