Get请求

259 阅读1分钟

get请求分为两种方式 query / querystring

1.query

返回JSON参数

router.get('/', async (ctx) => {
  console.log(ctx.query)
})

当在url中输入:

localhost:3000/?help=123

控制台打印的结果为:

{help: '123'}

2.querystring

返回String字符串

router.get('/', asnyc (ctx) => {
  console.log(ctx.querystring)
})

当在url中输入:

localhost:3000/?help=123

控制台打印的结果为:

'help=123'