vue 发送验证码 倒计时1分钟

数据绑定文字

<div class="HTtx32" @click="Yanma">{{Ytxfont}}</div>

data中定义

 data() {
    return {
      Ytxfont: "发送验证码",
      Traem: true
    };
  },

methods中 触发点击事件 判断 Traem true 或 false 进行状态判断 启动倒计时 和 清除倒计时 改变 Ytxfont 的文字内容 此方法 为es6 拼接字符串

Yanma() {
      if (this.Traem) {
        this.Traem = false;
        let langtime =60;
        let than=this
        let a = setInterval(function() {
          if (langtime == 0) {
            than.Traem = true;
            than.Ytxfont = "发送验证码";
            clearInterval(a);
          } else {
            langtime--;
            console.log(langtime);
            than.Ytxfont = `倒计时${langtime}秒`;
          }
        }, 1000);
      } else {
        console.log("不能点了")
      }
    },

清晰明了

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值