按鈕:
<button class="yzm" @click="countDown">{{content}}</button>
定義return:
content:'發送驗證碼',
totalTime: 60 ,
canClick: true //添加canClick
事件:
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)
},