我的问题类似于How to post query parameters with Axios? 我不需要发布,而是想要一个获取数据请求,并且我想将查询参数名称传递给请求。它在邮递员中有效,但在反应中无效。
const handleSubmit = async () => {
try {
const res = await axios.get(
"http://localhost:5000/api/products",
{},
{
params: {
name,
},
}
);
console.log(res.data);
} catch (err) {}
};
exports.retrieveProducts = (req, res) => {
Product.find(
{ name: { $regex: req.query.name, $options: "i" } },
(err, products) => {
if (err) res.status(500).json(err);
res.json(products);
}
);
};
Run Code Online (Sandbox Code Playgroud)