收藏
回答

Cant find variable:at request fail call

框架类型 问题类型 API/组件名称 终端类型 操作系统 微信版本 基础库版本
小程序 Bug wx.request 客户端 6.6.7 2.0.9


1. result is not defined;at App post function;at api request fail callback function

2. Can't find variable: result;at pages/home/home requestHomeData function;at api request fail callback function

后台发现好多这种错误,都是 result is not defined at api request fail callback function,但是相应的 method 里面并没有任何 result,而且我确定所有的 result 都做了空判断,官方能指点指点吗?

pages/home/home requestHomeData function:

requestHomeData: function () {
    let that = this;
    wx.login({
      success: function (res) {
        res.code && app.post(Url.home, {city: that.data.currentCityName, code: res.code}).then(res => {
          res.data && that.handleHomeData(res.data);
        });
      }
    });
  },

App post function:

/**
   * 封装 post 请求为 Promise
   * @param url
   * @param data
   * @param header
   * @returns {*|Promise<any>}
   */
  post: function (url, data, header = {}) {
    if (this.globalData.deviceSerialNumber) {
      header = {...header, 'device-serial-number': this.globalData.deviceSerialNumber};
    }
    return url && data && new Promise((resolve, reject) => {
      wx.request({
        url: url,
        method: 'POST',
        data: data,
        header: {
          'content-type': 'application/json', // 微信默认就是
          ...header
        },
        success: function (res) {
          resolve(res);
        },
        fail: function (res) {
          reject(res);
        }
      })
    });
  },



最后一次编辑于  2018-06-08
回答关注问题邀请回答
收藏

4 个回答

登录 后发表内容