注册帐号倒计时

1.htmljavascript

<div class="code-button">
                        <el-button type="text" :disabled="isDisabled"  @click="handleMobileNum()">{{buttonText}}</el-button>
                    </div>

2javascripthtml

isDisabled: false,
                buttonText: '点击获取验证码',
                time: '59',





handleMobileNum() {
                if (this.isDisabled == true) {
                    return;
                }
                if (this.form.mobile == '') {
                    this.$message.error('请填写手机号');
                    return;
                }
                // if (!(/^1[3456789]\d{9}$/.text(this.form.mobile))) {
                //     this.$message.error('手机号码格式错误');
                //     return;
                // }
                var data = {
                    mobile: this.form.mobile,
                    captcha_id: this.captcha_image_id,
                    captcha_code: this.form.captcha_code
                }
                this.$http.post('/sms/send/register', data).then(res => {
                    if (!res.success == true) {
                        this.$message.success('验证码发送成功!');
                        let that = this;
                        that.isDisabled = true;
                        let interval = window.setInterval(() => {
                            that.buttonText = that.time + '秒后可从新发送';
                            --that.time;
                            if (that.time <= 0) {
                                that.buttonText = '从新发送';
                                that.isDisabled = false;
                                window.clearInterval(interval);
                                that.time = '59'
                            }
                        }, 1000)
                    } else {
                        this.$message.error('发送失败,请重试');
                    }
                })
            },
相关文章
相关标签/搜索