【发布时间】:2025-12-25 19:55:11
【问题描述】:
我想在 post 请求中将一个对象从后端发送到前端。我在前端得到对象,但那里没有数据。
这是我在前端(Vue 3)上的功能:
backend2(e){
e.preventDefault();
fetch('http://localhost:5000/enemystrongest', {method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({enemyCards: this.enemysCards})})
.then((res) => {return res})
.then((res) => {console.log(res)})
},
这是我的后端 root.js (NodeJS):
router.post('/enemystrongest', (req, res, next) => {
let cards = req.body;
res.setHeader("Content-Type", "application/json")
res.send(findEnemyStrongest(cards));
});
然后我在开发工具/控制台中得到这个:
Response {type: 'cors', url: 'http://localhost:5000/enemystrongest', redirected: false, status: 200, ok: true, …}
body: (...)
bodyUsed: false
headers: Headers {}
ok: true
redirected: false
status: 200
statusText: "OK"
type: "cors"
url: "http://localhost:5000/enemystrongest"
[[Prototype]]: Object
谁能帮帮我?
【问题讨论】: