问题描述
如何获取url中传入的参数值?例如,我的网址是 /forgot-password?email=testing@example.com&token=fb49d692186dd4744af50446fad2f031
我想获取电子邮件和令牌的价值。我从文档中发现的只是关于作为参数值的段,该值从路由设置为 /user/:id
,这与我的情况不同。
解决方法
Strapi 使用 koa。
因此,您只需使用 ctx.request.query
。
在您的处理程序中:
async test(ctx) {
let queryObj = ctx.request.query
//use them...
}
对于您声明的请求,对象将包含:
{
email: 'testing@example.com',token: 'fb49d692186dd4744af50446fad2f031'
}