[英]Mongoose route isn't getting query data from axios function
Data being sent to the axios function isn't getting to the mongoose route in the back-end.发送到 axios function 的数据没有到达后端的 mongoose 路由。 The data is getting to the axios function from the front-end in react, but isn't making it to the back-end.数据在反应中从前端到达 axios function,但没有到达后端。
Front-end calling Axios前端调用Axios
const bugQuery = {
GroupID: "FRITOS",
};
this.props.getBugs(bugQuery);
Axios function Axios function
export const getBugs = (item) => (dispatch) => {
console.log(item);
axios.get("/api/bugs", item).then((res) =>
dispatch({
type: GET_BUGS,
payload: res.data,
})
);
};
Mongoose route Mongoose路线
router.get("/", (req, res) => {
console.log(req.body);
Bugs.find({ GroupID: req.body.GroupID }).then((items) => res.json(items));
console.log("Bugs loaded");
});
You cannot use req.body
in a GET method it's available just in POST, PUT and PATCH methods您不能在 GET 方法中使用req.body
它仅在 POST、PUT 和 PATCH 方法中可用
update: or just use request params like this更新:或者只使用这样的请求参数
export const getBugs = (item) => (dispatch) => {
console.log(item);
axios.get(`/api/bugs/${item.groupId}`).then((res) =>
dispatch({ type: GET_BUGS, payload: res.data, }) );
};
backend:后端:
router.get("/api/bugs/:id", (req, res) => {
console.log(req.params.id);
Bugs.find({ GroupID: req.params.id }).then((items) => res.json(items)); console.log("Bugs loaded");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.