小程序&vue.js 登录页面获取验证码倒计时

<button v-if="sendMsgDisabled" disabled>{{time + '秒后获取'}}</button>
<button v-else size="small" @click="sendCode">发送验证码</button>
data() {
    return {
        sendMsgDisabled: false,
        time: 60
    };
},
methods: {
    sendCode() {
        //将以下代码放入到发送验证码请求成功的回调中
        this.sendMsgDisabled = true
        let interval = setInterval(() => {
            if ((this.time--) <= 0) {
                this.time = 60
                this.sendMsgDisabled = false
                clearInterval(interval)
            }
        }, 1000)
    }
},

 1,308 total views,  2 views today

Revisions

No comments yet.

发表评论