Javascript 快速集成
尝试测试React+Express并遇到路由问题 快递:Javascript 快速集成,javascript,reactjs,express,Javascript,Reactjs,Express,尝试测试React+Express并遇到路由问题 快递: router.get('/testCall', function(req, res) { res.json([{id: 'test'}]); }) 反应: fetch('/testCall') .then((res) => { console.log(res); console.log(res.body); console.lo
router.get('/testCall', function(req, res) {
res.json([{id: 'test'}]);
})
反应:
fetch('/testCall')
.then((res) => {
console.log(res);
console.log(res.body);
console.log('end test');
res.json();
})
.then(res => console.log(res))
res变量不包含我的测试字符串,res.body变量包含“ReadableStream”。最终的res打印未定义。知道我做错了什么吗?这与前端和后端的集成无关,但与无法从“先到后”函数返回值有关。没有传递任何内容来记录以下内容。试一试
return res.json()
当你开始输入日志记录语句时,你可能会搞砸。这样做很好:
.then(res => res.json())
.then(console.log)
这与集成前端和后端无关,但与无法从first-then函数返回值有关。没有传递任何内容来记录以下内容。试一试
return res.json()
当你开始输入日志记录语句时,你可能会搞砸。这样做很好:
.then(res => res.json())
.then(console.log)
谢谢,这很有效。所以我猜日志记录返回未定义的值,然后我的then语句尝试打印该返回值?谢谢,这很有效。我猜日志记录返回未定义的值,然后我的then语句尝试打印该返回值?