如何在“?”之后访问GET参数在快递? [英] How to access the GET parameters after "?" in Express?
本文介绍了如何在“?”之后访问GET参数在快递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何获取这样的查询参数:
I know how to get the params for queries like this:
app.get('/sample/:id', routes.sample);
在这种情况下,我可以使用 req.params.id
获取参数(例如 2
in / sample / 2
)。
In this case, I can use req.params.id
to get the parameter (e.g. 2
in /sample/2
).
但是,对于像 / sample / 2?color = red
的url,如何访问变量 color
?
However, for url like /sample/2?color=red
, how can I access the variable color
?
我尝试了 req.params.color
,但没有起作用。 / p>
I tried req.params.color
but it didn't work.
推荐答案
所以,在查看表示参考,我发现 req.query.color
会把我要找的值返回给我。
So, after checking out the express reference, I found that req.query.color
would return me the value I'm looking for.
这篇关于如何在“?”之后访问GET参数在快递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文