这是我第一次使用axios而且遇到了错误.
axios.get(
`http://someurl.com/page1?param1=1¶m2=${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
我正在使用 Vue JS 2.5 和 Axios:
\n\n"vue": "^2.5.17",\n"vue-axios": "^2.1.4",\n"axios": "^0.18.0",\nRun Code Online (Sandbox Code Playgroud)\n\n我正在尝试像这样进行 POST 调用:
\n\nconst 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 });\nRun Code Online (Sandbox Code Playgroud)\n\n我也尝试过不使用“axiosConfig”参数。但每次它进入捕获时,都会显示以下消息:错误:网络错误
\n\n在浏览器的“网络”选项卡中,我得到 200 状态和良好的响应(带有有效的 json),它基本上可以工作,但 Axios 返回错误并且没有响应。
\n\n控制台还输出此警告: …