发完验证码60秒倒计内时不能再次发送

2020-05-13  本文已影响0人  温酒居士

使用的vue

timeout: true,
count: '',
timer: null,
            getCode() {
                const TIME_COUNT = 60;
                if (!this.timer) {
                    this.count = TIME_COUNT;
                    this.timeout = false;
                    this.timer = setInterval(() => {
                        if (this.count > 0 && this.count <= TIME_COUNT) {
                            this.count--;
                        } else {
                            this.timeout = true;
                            clearInterval(this.timer);
                            this.timer = null;
                        }
                    }, 1000)
                }
            }
 <el-button class="send" size="small" type="primary" @click="send(ruleForm.phone,true)" v-show="timeout">发送验证码
 </el-button>
 <el-button class="send" size="small" type="primary" disabled v-show="!timeout">{{count}}</el-button>
上一篇 下一篇

猜你喜欢

热点阅读