uniapp vue中的短信验证码

你说的曾经没有我的故事 提交于 2019-12-05 18:59:35
<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>                        

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!