小编har*_*ool的帖子

当状态为 200 ok 时,axios 发送网络错误

我正在使用以下 axios 查询在我的 Node.js Express 服务器上发送图片:

axios.post(this.server + 'images',
    formData, {
        crossdomain: true,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    }
).then(function (result) {
    console.log(result);
})
.catch(function (error) {
    console.log(error);
}); 
Run Code Online (Sandbox Code Playgroud)

图片现在在服务器上,但是,请看一下我在 Firefox 控制台中看到的奇怪行为,它显示“网络错误”,而 Axios 正在接收 200 状态!:

问题

POST http://localhost/images
[HTTP/1.1 200 OK 20ms]

Error: "Network Error"
    createError createError.js:16
    handleError xhr.js:81
Run Code Online (Sandbox Code Playgroud)

这是我的 node.js 后端 Cors 参数:

const cors = require("cors");
app.use(
  require("cors")({
    origin: function(origin, callback) {
      callback(null, origin);
    }
  })
);
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", req.headers.origin); // update to match the …
Run Code Online (Sandbox Code Playgroud)

node.js express axios vuejs2

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

标签 统计

axios ×1

express ×1

node.js ×1

vuejs2 ×1