vue实现发送短信倒计时和重发短信的功能

js实现发送短信倒计时功能

HTML代码部分

javascript 复制代码
        <el-button @click="queryBtn()" type="primary">发送短信({{countDown}})</el-button>
        <el-button @click="resetBtn()" type="danger" :disabled="resetBtndisab">重发</el-button>

JS代码部分

javascript 复制代码
export default {
    data(){
        return {
            countDown:60, // 默认时间60秒
            countDownTimeout:null,  // 倒计时计数器
            resetBtndisab:true, //重发按钮初始值为不可用
        }
    },
    methods:{
            // 查询按钮
            queryBtn(){
                 this.doCountDown()
            },
            // 重置按钮
            resetBtn(){
                 this.$message({
                        message: '短信验证码已发送,请注意查收!',
                        type: 'success'
                 });
                 this.resetCountDown();
                 this.resetBtndisab=true
            },
            // 倒计时开始
            doCountDown(){
                this.countDownTimeout=setTimeout(()=>{
                    this.countDown--;
                    if(this.countDown<=0){
                            this.resetBtndisab=false
                    }else{
                        this.doCountDown(this.countDown)
                    }
                },1000)
		    },
            // 重置倒计时
            resetCountDown(){
                clearTimeout(this.countDownTimeout);
                this.countDown=60;
            }

    }
}

实际展示效果



相关推荐
码事漫谈2 小时前
当AI开始“思考”:我们是否真的准备好了?
前端·后端
许杰小刀3 小时前
ctfshow-web文件包含(web78-web86)
android·前端·android studio
我是Superman丶3 小时前
Element UI 表格某行突出悬浮效果
前端·javascript·vue.js
恋猫de小郭3 小时前
你的代理归我了:AI 大模型恶意中间人攻击,钱包都被转走了
前端·人工智能·ai编程
xiaokuangren_4 小时前
前端css颜色
前端·css
Huanzhi_Lin4 小时前
关于V8/MajorGC/MinorGC——性能优化
javascript·性能优化·ts·js·v8·新生代·老生代
hoiii1874 小时前
C# 基于 LumiSoft 实现 SIP 客户端方案
前端·c#
anOnion4 小时前
构建无障碍组件之Meter Pattern
前端·html·交互设计
小码哥_常5 小时前
Spring Boot配置diff:解锁配置管理新姿势
前端
小码哥_常5 小时前
告别onActivityResult!Android数据回传的3大痛点与终极解决方案
前端