如何在'koa-router'中匹配URL'/ index?id = xxx'时如何获得'id'? 网络上的大多数文章通常使用url lick'/ index /:id',但后端接口并非如此。
How can i get the 'id' when i want to match url like '/index?id=xxx' in koa-router? most articles on the web usually use url lick '/index/:id',but the back-end interfaces are not the case.
最满意答案
它在后端API上的工作方式相同,当您向Web服务器发出GET请求时,它会解析查询字符串并使用这些值为您提供预期的响应。
当使用koa-router处理GET请求时,您可以指定查询字符串(如'/ index /:id'),并在代码中使用该值,您只需执行
var id = ctx.request.query.id;
It does work the same on a back-end API, when you make a GET request to a web server it parses the query-string and uses the values to give you the intended response.
When handling a GET request using koa-router you can specify the query string, such as '/index/:id', and to consume the value in your code you would simply do
var id = ctx.request.query.id;
更多推荐
发布评论