3 回答
![?](http://img1.sycdn.imooc.com/533e4c5600017c5b02010200-100-100.jpg)
TA贡献1719条经验 获得超6个赞
代码在 Content-Type 中声明主体将是 URL 字符串编码的,但在主体中它被赋予了一个 JavaScript 对象。似乎 Axios 客户端不会将该 body 对象转换为 url 编码值(即 from {a: 5, b: 2}
to "a=5&b=2"
)。代码需要一个函数来转换它。一个流行的是qs。
否则,您的数据可能会被转换为字符串,该.toString()
方法将为您提供"[object Object]"
,您应该能够在开发人员工具的网络选项卡中看到这一点。
![?](http://img1.sycdn.imooc.com/5333a1d100010c2602000200-100-100.jpg)
TA贡献1813条经验 获得超2个赞
Axios 处理错误的方式不同。
找出真正的问题所在。
您应该使用 error.request 来检查您提出的请求是否有错误
并使用 error.response 从服务器获取错误反馈
axios({ method: 'post', url: 'https://app/login', body: body1, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .then (res => { if (res.status === 200) { console.log(res) } }).catch(err => { if(err.request){ console.log(err.request) } if( err.response){ console.log(err.response) } });
![?](http://img1.sycdn.imooc.com/5333a2320001acdd02000200-100-100.jpg)
TA贡献1818条经验 获得超3个赞
Localhost:3000/api/products 404 错误 您没有在 server.js 上创建 res.get("/api/products") 或者您没有设置代理。检查下面的代理设置。
代理错误:无法代理请求 /api/products 检查:
前端/package.json
{ "name": "frontend", "proxy": "http://127.0.0.1:5000", ... }
停止运行前端和后端
先运行后端
启动
然后前端
cd 前端 npm start
添加回答
举报