你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

egg 获取传值参数

2021/12/11 8:19:38

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