<template>
<div> {{ codeBtnText }} </div>
</template>
<script>
export default {
data() {
return {
btnOptFlag: false,
codeBtnText: ‘获取验证码’,
outTime: 60,
timer: null
}
},
methods: {
sendCode() {
if(this.btnOptFlag) return
this.btnOptFlag = true
if(!this.timer){
this.timer = setInterval( () =>{
this.codeBtnText = this.outTime + ‘s后重新发送’
this.outTime = this.outTime - 1
if(this.outTime < 0) {
clearInterval(this.timer)
this.codeBtnText = ‘获取验证码’
this.outTime = 60
this.timer = null
this.btnOptFlag = false
}
}, 1000)
}
}
}
</script>