【发布时间】:2019-04-16 04:58:10
【问题描述】:
这是我的代码,它由 Js 文件和 React 文件组成。
//
// JS File
//
...
app.post('/searchResult',function(req,res)
{
res.send(searchValue);
console.log(`----------------------------`);
console.log(`Search Result :`+ searchValue);
})
...
//
// React File
//
...
axios.post(BASE_URL + '/searchResult')
.then(res =>
{
dataResult = res;
console.log(`The result :`+ dataResult);
})
...
//
//
//
结果:[object Object]
有什么解决办法吗?
【问题讨论】:
-
在你的 api 中返回 json.... 像这样返回 res.json(searchValue)
-
在你的 react 应用中,尝试 console.log(res.data)
-
@sathishkumar,我这样放,结果还是[object Object] app.post('/searchResult',function(req,res) { res.send(searchValue); console. log(
----------------------------); console.log(Search Result :+ searchValue); res.json(searchValue) }) -
@Israelkusayev 我尝试 console.log(res.data) 但它什么也没显示。这是否意味着它无法传递值?
标签: javascript node.js reactjs axios