Node.js 使用Express和Axios访问传递的对象
在客户端,我有:Node.js 使用Express和Axios访问传递的对象,node.js,reactjs,express,mongoose,axios,Node.js,Reactjs,Express,Mongoose,Axios,在客户端,我有: handleChangeSave(values, id) { axios.post('/api/users/change' + id, JSON.stringify(values)) .then(resp => { console.log(resp.data); }) .catch(function (error) { console.log(error);
handleChangeSave(values, id) {
axios.post('/api/users/change' + id, JSON.stringify(values))
.then(resp => {
console.log(resp.data);
})
.catch(function (error) {
console.log(error);
});
}
在服务器端,我试图查询对象,但它返回为空,而实际上它不是空的
router.post('/users/change:id', (req, res) => {
User.findById({ '_id': req.params.id }, (err, user) => {
if(err) return res.status(500).send(err);
let Values = req.query;
console.log(Values); // returns {}
})
});
键入错误
/users/change/:id
,并使用正文解析器
作为post获取请求正文
body@MukeshSharmaIdk,如果它的问题,但请提交作为一个答案,我会标记为正确的。非常感谢。