<template>
<div>
<el-button type="primary" class="button" :disabled="canClick== false ? true : false" @click="countDown">
{{content}}
</el-button>
</div>
</template>
<script>
export default {
data () {
return {
content: '发送验证码', // 按钮里显示的内容
totalTime: 60 , //记录具体倒计时时间
canClick: true //添加canClick
}
},
methods: {
countDown () {
if (!this.canClick) return //改动的是这两行代码
this.canClick = false
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
this.canClick = true
}
},1000)
},
}
}
</script>
<style scoped>
</style>