uniapp實現發送驗證碼倒計時效果


<button type="primary"  @click='getVerificationCode' :disabled='disabled'>{{btntxt}}</button>
<script>
    import Vue from 'vue';
    export default Vue.extend({
        data() {
            return {
                btntxt: '發送驗證碼',
                seconds: 60,
                disabled: false,
            }
        },
        methods: {
            getVerificationCode() {
                const timer = setInterval(() => {
                    this.btntxt = this.seconds + '秒再試';
                    this.seconds--;
                    this.disabled = true;
                    if(this.seconds === 0){
                        clearInterval(timer);
                        this.btntxt = '發送驗證碼';
                        this.seconds = 60;
                        this.disabled = false
                    }
                }, 1000);
                
            }
        },
        
    });
</script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM