【问题标题】:How to detect response in VueJS?如何检测 VueJS 中的响应?
【发布时间】:2020-04-04 14:44:24
【问题描述】:

我请求有知识的人的帮助 我在 Vue.js(Vuex 也是)上创建了一个 RESTfull API 项目 我遇到了小问题 我向其发送请求的服务器已关闭,为什么 idn 有人可以告诉我如何从响应中检测到此消息

此响应没有任何质量、错误、状态、状态文本、文本、预览和响应 此字段全部为空 如果有人对此或某些信息有经验,我将非常感激

【问题讨论】:

    标签: ajax vue.js vuejs2 xmlhttprequest vuex


    【解决方案1】:

    您可以这样做来处理这些情况:

    submitRequest() {
      axios.post('/api/test', this.testData)
        .then(response => {
          // handle success
        })
        .catch(function(error) {
          // handle error
          if (error.response) {
            // The request was made and the server responded with a status code
          } else if (error.request) {
            // YOU CAN HANDLE IT HERE
            // The request was made but no response was received
            // `error.request` is an instance of XMLHttpRequest in the browser
            console.log(error.request);
          } else {
            // Something happened in setting up the request that triggered an Error
          }
        });
    }

    【讨论】:

      猜你喜欢
      • 2020-01-15
      • 2017-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-13
      • 2014-12-03
      相关资源
      最近更新 更多