VUE发送短信倒计时组件代码

组件源码

<template>

<button class="sendSmsBtn" :class="disabled?'dissendSmsBtn':''" type="button" v-on:click="run" :disabled="disabled || time > 0">{{ text }}</button>
</template>


<script>
export default{
props: {
        second: {
            type: Number,
            default: 60
        }
    },
    data:function () {
     return {
        time: 0,
        disabled:false
     }
    },
    methods: {
        run: function () {
         this.$emit('run');
        },
        start: function(){
         this.time = this.second;
         console.log(this.disabled);
         this.timer();
        },


        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 后重获取' : '获取验证码';
        }
    }
}
</script>


<style>
.sendSmsBtn{
position: absolute;
right: 0px;
height: 34px;
    line-height: 34px;
    border-radius: 3px;
    background: #ffb400;
    border: none;
    padding: 0 6px;
    color: #fff;
    display: inline-block;
    width: 90px;
    top: 12px;
}
.sendSmsBtn.dissendSmsBtn{
background-color: #FFE39F;
}

</style>




引用页面

import timerBtn from '@/components/timerBtn/timerBtn';


注册组件

components: {
timerBtn
}


使用

<timerBtn ref="timerbtn" class="btn btn-default" @run="sendCode"></timerBtn>


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值