<button class="button" @click="countDown">
{{content}}
</button>
...
data () {
return {
content: '发送验证码', // 按钮里显示的内容
totalTime: 60 //记录具体倒计时时间
}
},
methods: {
countDown () {
this.content = this.totalTime + 's后重新发送' //这里解决60秒不见了的问题
let clock = window.setInterval(() => {
this.totalTime--
this.content = this.totalTime + 's后重新发送'
if (this.totalTime < 0) { //当倒计时小于0时清除定时器
window.clearInterval(clock)
this.content = '重新发送验证码'
this.totalTime = 60
}
},1000)
},