get传值:
在koa2中,get传值通过request接收,但是接收的方式有两种
query:返回的是格式化好的参数对象
querystring:返回的是请求字符串
router.get('/home',async (ctx) => {
console.log(ctx.query); //{id:'123'} 等价于ctx.request.query/*推荐*/
console.log(ctx.querying); //id=123&name=slj 等价于ctx.request.querystring
console.log(ctx.request); //打印出一个详细的ajax请求
})
获取动态路由值:
router.get('/newsdetails/:id',async (ctx) => {
console.log(ctx.params); //{id:'123'}
})