相关疑难解决方法(0)

反应:Axios网络错误

这是我第一次使用axios而且遇到了错误.

  axios.get(
    `http://someurl.com/page1?param1=1&param2=${param2_id}`
  )
  .then(function(response) {
    alert();
  })
  .catch(function(error) {
    console.log(error);
  });
Run Code Online (Sandbox Code Playgroud)

使用正确的URL和参数,当我检查网络请求时,我确实从我的服务器得到了正确的答案,但是当我打开控制台时,我发现它没有调用回调,而是发现了错误.

错误:网络错误堆栈跟踪:createError @ http:// localhost:3000/static/js/bundle.js:2188:15 handleError @ http:// localhost:3000/static/js/bundle.js:1717:14

javascript reactjs axios

17
推荐指数
5
解决办法
3万
查看次数

即使状态为 200 并且有响应,Axios POST也会返回“网络错误”

我正在使用 Vue JS 2.5 和 Axios:

\n\n
"vue": "^2.5.17",\n"vue-axios": "^2.1.4",\n"axios": "^0.18.0",\n
Run Code Online (Sandbox Code Playgroud)\n\n

我正在尝试像这样进行 POST 调用:

\n\n
const data = querystring.stringify({\n                \'email\': email,\n                \'password\': password,\n                \'crossDomain\': true, //optional, added by me to test if it helps but it doesn\'t help\n            });\n\nvar axiosConfig = {\n                    headers: {\n                        \'Content-Type\': \'application/x-www-form-urlencoded\',\n                        // "Access-Control-Allow-Origin": "*",\n                        \'Accept\': \'*\',\n                    }\n                };\n\naxios.post(url, data, axiosConfig)\n                .then((response) => {\n                    console.log(\'response\');\n                    console.log(response);\n                })\n                .catch((error) => {\n                    console.log(\'error\');\n                    console.log(error);\n                });\n
Run Code Online (Sandbox Code Playgroud)\n\n

我也尝试过不使用“axiosConfig”参数。但每次它进入捕获时,都会显示以下消息:错误:网络错误

\n\n

在浏览器的“网络”选项卡中,我得到 200 状态和良好的响应(带有有效的 json),它基本上可以工作,但 Axios 返回错误并且没有响应。

\n\n

控制台还输出此警告: …

javascript npm vue.js axios vuejs2

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

axios ×2

javascript ×2

npm ×1

reactjs ×1

vue.js ×1

vuejs2 ×1