定时器
<div>
<span v-show="show === 1" @click="getCode">获取验证码</span>
<span v-show="show === 2">{{ count }} s</span>
<span v-show="show === 3" @click="getCode">重发</span>
</div>
return {
show: 1,
count: '',
timer: null
}
methods: {
getCode () {
const TIME_COUNT = 10
if (!this.timer) {
this.count = TIME_COUNT
this.show = 2
this.timer = setInterval(() => {
if (this.count > 0 && this.count <= TIME_COUNT) {
this.count--
} else {
this.show = 3
clearInterval(this.timer)
this.timer = null
}
}, 1000)
}
}
}