egg 获取传值参数
1. 路由配置:
router.post('/home/parameter/:id', controller.home.parameter);
2. 处理函数:
async parameter() {
const id = this.ctx.params.id
const name = this.ctx.query.name
const body = this.ctx.request.body
this.ctx.body = {
msg: 'ok',
name,
id,
body
}
}
3. 结果如图:

4. 总结
// get 请求
const id = this.ctx.params.id
const name = this.ctx.query.name
// post 请求
const id = this.ctx.params.id
const name = this.ctx.query.name
const body = this.ctx.request.body
