uniapp vue中的短信驗證碼


<template>
    <view class="content">
        <view class="input-item yzs">
            <text class="tit">驗證碼</text>
            <button class="tit" @tap="sendCode" :disabled="disabled">{{send}}</button>
        </view>
    </view>
</template>
<script>
    export default {
        data() {
            return {
                disabled:false,
                send:'發送驗證碼'
            }
        },
        methods: {
            sendCode(){
                let self = this
                //驗證碼
                self.disabled = true;
                var time = 10;                //時間為10s,可以按情況更改 
                var timer = setInterval(fun, 1000);  //設置定時器 
                function fun() { 
                    time--; 
                    if(time>=0) { 
                        self.send = time + "s后重新發送"; 
                    }else if(time<0){ 
                        self.send = "重新發送驗證碼"; 
                        self.disabled = false;  //倒計時結束能夠重新點擊發送的按鈕 
                        clearInterval(timer);  //清除定時器 
                        time = 10;  //設置循環重新開始條件 
                    } 
                } 
            },
        }
    }
</script>                        

 

 

有錯誤請告訴我,我會及時改正,謝謝


免責聲明!

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



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