如何在express中获取请求参数
how to get request param in express
这是我的代码:
router.all('/trips:key?', (req, res) => {
console.log("Yeah")
console.log(req.params.key)
})
GET http:localhost:8080/trips?keyword=kong
输出:
Yeah
undefined
如何在 keyword
中获取值 kong
谢谢。
希望这对 GET http:localhost:8080/trips?keyword=kong
有用
你的路线应该是/trips
而不是/trips:key?
router.all('/trips', (req, res) => {
console.log("Yeah")
console.log(req.query.keyword)
})
这是我的代码:
router.all('/trips:key?', (req, res) => {
console.log("Yeah")
console.log(req.params.key)
})
GET http:localhost:8080/trips?keyword=kong
输出:
Yeah
undefined
如何在 keyword
kong
谢谢。
希望这对 GET http:localhost:8080/trips?keyword=kong
你的路线应该是/trips
而不是/trips:key?
router.all('/trips', (req, res) => {
console.log("Yeah")
console.log(req.query.keyword)
})