vue获取验证码按钮60s倒计时
两个按钮:
```
<el-button v-if="checkFlag" @click="sendmail">获取验证码</el-button>
<el-button v-if="!checkFlag" >{{ checkText }}</el-button>
```
data数据:
```
data() {
return {
checkFlag: false,
checkText: "",
timer: "",
}
}
```
click方法:
```
sendmail () {
if (checkFlag) {
return
}
if (email === '') {
return this.$toast('请输入邮箱')
}
$api.sendmail({
email:email
}).then(res=>{
countDown(60)
checkFlag = true
})
},
```
倒计时方法:
```
countDown (val) {
if (val <= 0) {
checkFlag = false
checkText = '发送验证码'
return
}
let num = val
num--
checkText = '重新获取' + num
timer = setTimeout(() => {
countDown(num)
}, 1000)
},
```