Cant find variable:at request fail call
发布于 6 年前 作者 tao69 18048 次浏览 来自 问答

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

  1. 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](/user/param) url
   * [@param](/user/param) data
   * [@param](/user/param) header
   * [@returns](/user/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);
        }
      })
    });
  },

4 回复

我也遇到同样的问题,不知是什么原因?@官方

你好,光是描述错误信息没有对应的代码,也很难定位到问题的~

我也遇到同样的问题,不知是什么原因?@官方

回到顶部