微信小程序短信验证码倒计时不会开始 ,请求支援

点击获取验证码后 倒计时不会启动 ,短信验证码正常能接收 ,下面是前端js

  // 获取真实姓名 手机号
  getData(){
    let that = this;
    wx.showLoading({
      mask: true
    })
    wx.request({
      url: app.d.WEB_URL +"/api/user/index",
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        token:wx.getStorageSync('token')
      },
      success(res) {
        console.log(res)
        wx.hideLoading();
        if(res.data.code=="103"){
          app.nologin()
        }else if (res.data.code == 1) {
          that.setData({
            mobile:res.data.data.mobile,
            name:res.data.data.realname,
          })
          if(res.data.data.mobile!=''){
            that.setData({
              mobileDisbled:true
            })
          }
          if(res.data.data.realname!=''){
            that.setData({
              nameDisbled:true
            })
          }
        }else{
          wx.showToast({
            title: res.data.msg,
            mask: true,
            icon: 'none'
          })
        }
      }
    })
  },

  // 图片一直旋转动画
  refreshList: function () {
    var that = this
    
    // 重新获取验证码
    that.setData({
      pintuShow:'none'
    })
    setTimeout(function(){
      that.setData({
        pintuShow:'block'
      })
    },100)
  },
  
  mobileInput(e) {
    this.setData({
      mobile: e.detail.value
    })
  },
  nameInput(e) {
    this.setData({
      name: e.detail.value
    })
  },
  codeInput(e) {
    this.setData({
      code: e.detail.value
    })
  },

  codeTopt(){
    if(this.data.mobile==''){
      wx.showToast({
        title: '请输入联系方式',
        duration: 2000,
        icon: 'none'
      });
    }else {
      this.setData({
        pintuShow:'block',
        ptshow:true,
      })
    }
  },
  onMyEvent: function (e) {
    //通过事件接收插件数据:中奖id与剩余抽奖次数
    console.log(e.detail)
    if(e.detail.result=='ok'){
      this.countDown();
      this.setData({
        pintuShow:'none',
        ptshow:false,
        is_hui :''
      })
    }else {
      this.setData({
        pintuShow:'none',
        ptshow:false,
      })
    }
  },
  codeBtn() {
    var that = this
    wx.request({
      url: app.d.WEB_URL +"/api/index/sendMsg",
      method: 'post',
      data: { token:wx.getStorageSync('token'),mobile: that.data.mobile},
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res)
        wx.hideLoading()
        if (res.data.code == 1) {
          wx.showToast({
            title: res.data.msg,
            duration: 2000,
            icon: 'none'
          });
          that.setData({
            disabled: true,
          })
          that.countDown();
        } else {
          wx.showToast({
            title: res.data.msg,
            duration: 2000,
            icon: 'none'
          });
        }
      },
      fail: function () {
        // fail
        wx.showToast({
          title: '网络异常!',
          duration: 2000,
          icon: 'none',
          icon: 'none'
        });
      }
    });
  },
  // 倒计时
  countDown() {
    //倒计时
    let time = 60;
    let timer = setInterval(() => {
      if (time == 0) {
        clearInterval(timer);
        var codetext = '获取验证码';
        this.setData({
          disabled: true,
          codetext: codetext,
        })
      } else {
        this.setData({
          disabled: false,
          codetext: time + '秒',
        })
        time--
      }
    }, 1000)
  },

```       

倒计时一般是前端写的,和后端没关系的吧


<view catchtap="getVerifyCode" 
wx:if="{{flag}}"
class="rui-btn rui-order-btn rui-order-go-pay-btn rui-dfs24 rui-send-class" 
style="width:165rpx;height:50rpx;">{{sendText}}</view>

<view wx:if="{{!flag}}" 
class="rui-btn rui-order-btn rui-send-after-btn rui-dfs24 rui-send-after-class" 
style="width:165rpx;height:50rpx;">{{codeText}}</view>


Component({
  externalClasses:[
    'rui-send-class',
    'rui-send-after-class',
  ],
  properties: {
    time: {
      type: Number,
      value: 120
    },
    type: {
      type: Number,
      value: 0
    },
    sendText: {
      type: String,
      value: '获取验证码'
    },
    sendAfterText: {
      type: String,
      value: 's后重发'
    },
    phone: String
  },
  data: {
    flag: true,
    timer: null,
    sec: 0
  },
  ready(){
    this.data.sec = this.data.time;
    this.setData({ codeText: `${this.data.sec}${this.data.sendAfterText}`})
  },
  useMethods: ['Validator'],
  methods: {
    validatorParams(flag, phone){
      return new this.Validator([{
        rule: !flag,
        msg: '验证码已发送,请等待!'
      },{
        rule: !phone,
        msg: '手机号码不能为空!'
      },{
        rule: !this.$.isMobile(phone),
        msg: '手机号码不正确!'
      }]).start()
    },
    getVerifyCode(e){
      let { flag, phone, type } = this.data
      let params = {phone, type}
      if(!this.validatorParams(flag, phone)){return;}
      this.setData({flag: false})
      this.countDown();
      this.$axios._login().then(code => {
        params.code = code;
        this.$axios._requestpost('sendPhoneVerifyCodeUrl', params).then(console.log).catch(console.log)
      })
    },
    countDown(){
      let sec = this.data.sec;
      this.data.sec = --sec;
      this.setData({ codeText: `${sec}${this.data.sendAfterText}`})
      if(sec > 0){
        this.data.timer = setTimeout(res => {
          this.countDown();
        },1000);
      } else {
        this.setData({flag: true});
        this.data.sec = this.data.time;
        clearTimeout(this.data.timer);
      }
    }
  }
})