问题:post请求-URL传参方式 axios返回200状态码(请求成功),数据不更新却走进了catch里面

原因: then()方法里的逻辑代码错误,所以接口走进了catch,具体如下:

post: function (url, params, successCallBack, errorCallBack) {
    service.post(url, params, FORM_DATA_TYPE)
      .then(function (response) {
        if (response && response.code.toString() === "200") {
          successCallBack(response);
        } else {
        debugger;
          errorCallBack(response);
        }
      }).catch(function (error) {
        errorCallBack(error);
      })
  }



searchTag: "/graph/searchGraphTag",  // 主体字典 列表
    searchGraphTag: function (params, succesCallback, errorCallback) {
      service.postA(this.searchTag + '?' + params, succesCallback, errorCallback)
    },

 let params = 'tagName='+that.tagName+'&pageNo='+that.pageNum+'&pageSize='+that.pageSize;
 that.httpService.configManage.searchGraphTag(
        params,
        function(res) {
          if (res.code == '200') {
            that.mainData = res.data.data;
            // that.elMsg(res.msg,'success',true)
            that.totals = Number(res.data.recordsTotal);
          }
        },
        function(error) {
          that.elMsg(error.msg, "error", true);
        }
      );

 接口成功却没有数据,检查发现是因为then()的逻辑不对,多传了一个参数,所以进入了catch里面;修改如下:

postA: function ( params, successCallBack, errorCallBack) {
    service.post( params, FORM_TYPE)
      .then(function (response) {
        if (response && response.code.toString() === "200") {
          successCallBack(response);
        } else {
          errorCallBack(response);
        }
      }).catch(function (error) {
        errorCallBack(error);
      })
  },

searchTag: "/graph/searchGraphTag",  // 主体字典 列表
    searchGraphTag: function (params, succesCallback, errorCallback) {
      service.postA(this.searchTag + '?' + params, succesCallback, errorCallback)
    },

完美解决 

Logo

前往低代码交流专区

更多推荐