發送短信驗證碼,60秒倒計時重發

<template>
    <el-input size="small" placeholder="請輸入驗證碼" v-model="phoneCode">
        <el-button  :disabled="disSend" size="small" slot="append" @click="send">{{BtnName}}</el-button>
    </el-input>
</template>

<script>
    export default {
        data() {
            return {
                phoneCode: '',
                BtnName: '發送驗證碼',
                disSend:false
            }
        },
        methods: {
            send() {
                this.disSend = true
                this.$alert('已向手機號13908056224發送短信', '溫馨提示', {
                    confirmButtonText: '確定',
                    callback: action => {
                        let count = 60;
                        let timer = null
                        if (!timer) {
                            timer = setInterval(() => {
                                if (count > 1) {
                                    count--;
                                    this.BtnName = count + '秒後重發'
                                } else {
                                    clearInterval(timer);
                                    timer = null;
                                    this.disSend = false
                                    this.BtnName = '發送驗證碼'
                                }
                            }, 1000)
                        }
                    }
                });
            }
        }
    }
</script>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章