1、通过get方式请求获取参数的方式有两种
通过上下文获取
通过request获取
获得的格式有两种:query与querystring
注意:querystring为小写,驼峰格式会导致无法获取
2、示例
const Koa = require('koa');
const app = new Koa();
app.use(async(ctx) => {
let url = ctx.url; let request = ctx.request;
let req_query = request.query;
let req_queryString = request.querystring; let ctx_query = ctx.query;
let ctx_queryString = ctx.querystring;
ctx.body = {
url,
req_query,
req_queryString,
ctx_query,
ctx_queryString
}
}) app.listen(3000)
console.log("demo is starting at port 3000")