博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vue 短信验证码
阅读量:6958 次
发布时间:2019-06-27

本文共 1020 字,大约阅读时间需要 3 分钟。

Vue.component('timerBtn',{

    template: '<button v-on:click="run" :disabled="disabled || time > 0">{
{ text }}</button>',
    props: {
        second: {
            type: Number,
            default: 60
        },
        disabled: {
            type: Boolean,
            default: false
        }
    },
    data:function () {
        return {
            time: 0
        }
    },
    methods: {
        run: function () {
            this.$emit('run');
        },
        start: function(){
            this.time = this.second;
            this.timer();
        },
        stop: function(){
            this.time = 0;
            this.disabled = false;
        },
        setDisabled: function(val){
            this.disabled = val;
        },
        timer: function () {
            if (this.time > 0) {
                this.time--;
                setTimeout(this.timer, 1000);
            }else{
                this.disabled = false;
            }
        }
        
    },
    computed: {
        text: function () {
            return this.time > 0 ? this.time + 's 后重获取' : '获取验证码';
        }
    }

});

 

 

 
 

var vm = new Vue({

    el:'#app',
    methods:{
        sendCode:function(){
            vm.$refs.timerbtn.setDisabled(true); //设置按钮不可用
            hz.ajaxRequest("sys/sendCode?_"+$.now(),function(data){
                if(data.status){
                    vm.$refs.timerbtn.start(); //启动倒计时
                }else{
                    vm.$refs.timerbtn.stop(); //停止倒计时
                }
            });
        },
    }
});

 

 

转载于:https://www.cnblogs.com/dunke/p/7779296.html

你可能感兴趣的文章
#15、#16 网络的基本构成与网络的几协议
查看>>
视频客户端电脑版去广告补丁V 1.0
查看>>
HTTP 499 状态码 nginx下 499错误
查看>>
shell 九九乘法表
查看>>
接口调用-http和https
查看>>
undo backup optimization does not work on 11.2.0.1?
查看>>
F5 的SNAT的irules相关配置
查看>>
安装redis(3.2.9)
查看>>
shell脚本之一
查看>>
oracle 12c 关闭统计信息收集和启用统计信息收集
查看>>
修复微商城提交购物车时部分手机号码不识别
查看>>
基于 HTML5 Canvas 的 3D 模型列表贴图
查看>>
ORA-00000 这是什么报错!
查看>>
lvs-dr简单配置
查看>>
hadoop配置lzo
查看>>
脚本调试:一次换行符导致的报错
查看>>
mysql 之 主从同步(单向同步和双向同步)
查看>>
Nginx负载均衡、ssl原理、生成ssl密钥对、Nginx配置ssl
查看>>
经典的MySQL 数据备份校验daemon程序
查看>>
logrotate日志轮询
查看>>