![](/img/trans.png)
[英]Nodejs .Unable to send oauth v1 params in get request with axios
[英]How to acess axios params in nodejs get request
我正在使用 axios 向 API 發送獲取請求,但無法訪問該請求中傳遞的參數。
這是我的代碼:API 請求
axios.get('http://localhost:4000/students',{
params: {
category:"indoor"
}
})
請求處理
router.route('/').get((req, res) => {
console.log(req.params.category);
studentSchema.find({category:req.params.category},(error, data) => {
if (error) {
return next(error)
} else {
res.json(data)
}
})
})
當沒有給定參數時,路由正常工作。
控制台日志(req.params.category); 給出 output 未定義。
希望你有問題...
我相信你正在嘗試做的事情與 Axios 無關,要獲取查詢參數,在代碼的服務器端,你需要使用請求的屬性query
,如下所示:
let category = req.query["category"];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.