收藏
回答

小程序请求接口成功后调用wx.hideLoading(),偶尔出现无法关闭loading的情况

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.hideLoading() 微信iOS客户端 8.0.56 3.7.12
getCode: function () {
    if (this.data.isDisabled) {
      return;
    }
    let self = this;
    if (this.data.phone_num.trim() == '') {
      wx.showToast({
        title'请输入手机号',
        icon'none'
      })
      return;
    }


    if (!/^1[0-9]{10}$/.test(self.data.phone_num)) {
      wx.showToast({
        title'手机号格式错误',
        icon'none'
      })
      return;
    }


    wx.showLoading();
    wx.request({
      url: util.baseUrl + 'api/phoneGetCode',
      method'POST',
      data: {
        telthis.data.phone_num,
        zone_id:app.globalData.zone_id,
        s'/api/phoneGetCode'
      },
      successres => {
        wx.hideLoading();
        if(res.statusCode && res.statusCode !== 200) {
          wx.showToast({
            title'服务器错误'+res.statusCode,
            icon'none',
          })
          app.postErrorMsg('接口api/phoneGetCode:'+res.statusCode+JSON.stringify({res}))
          return
        }
        if (res.data.err_code == 200) {
          wx.showToast({
            title: res.data.err_msg,
            icon'none',
            duration3000
          })


          // 每60s 发送一次验证码
          let num = 60;
          wx.setStorageSync('send_sms_timeStamp'Date.parse(new Date())/1000)
          let intervalId = setInterval(function () {
            if (num >= 0) {
              self.setData({
                code_text: num + 's',
                isDisabledtrue
              })
              num -= 1;
            } else {
              self.setData({
                code_text'获取验证码',
                isDisabledfalse
              })
              clearInterval(intervalId);
            }
          }, 1000);
        } else if (res.data.err_code == 100) {
          wx.showModal({
            title'查询不到该账号',
            content'请检查您输入的号码是否有误。如输入正确但无法登陆,请联系咨询助理,我们将及时帮您解决。',
            showCancelfalse
          })
        } else {
          wx.showToast({
            title: res.data.err_msg,
            icon'none',
            duration3000
          })
        }
      },
      fail(err) {
        wx.hideLoading();
        wx.showToast({
          title'发送请求失败',
          icon'none'
        });
        app.postErrorMsg('接口api/phoneGetCode:'+JSON.stringify({err}))
      }
    })
  },


小程序点击发起请求,请求接口成功后调用wx.hideLoading(),偶尔 出现无法关闭loading的情况,并且调用了后面的wx.showToast也没有toast弹窗,感觉频率挺高的,很容易就复现一次,手机和工具都有出现过

另外工具的版本:1.06.2503281 基础库:3.8.3

回答关注问题邀请回答
收藏
登录 后发表内容