Egg: 自定义Controller基类调用不到

Created on 17 Feb 2017  ·  8Comments  ·  Source: eggjs/egg

按官网教程,自定义Controller基类

module.exports = app => {
  class CustomController extends app.Controller {
    success(data) {
      this.ctx.body = {
        success: true,
        data,
      };
    }
  }
  app.Controller = CustomController;
}

在Controller中调用不到

module.exports = app => {
  return class PostController extends app.Controller {
    * list() {
      this.success({id: 1});
    },
  };
};
bug question

Most helpful comment

删掉依赖重新安装下就可以了

All 8 comments

你的第一段代码在哪里写的?

@dead-horse 在app.js中

egg-core 里面设置成不允许修改了,我修复一下,顺便写一个 example

定义成 getter 了,直接在 constructor 里面设置好了

删掉依赖重新安装下就可以了

同样的问题,已解决,谢谢大家~

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhaofinger picture zhaofinger  ·  3Comments

Webjiacheng picture Webjiacheng  ·  3Comments

skyyangpeng picture skyyangpeng  ·  3Comments

wujianling picture wujianling  ·  3Comments

ycvcb123 picture ycvcb123  ·  3Comments