-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Controller中下面exports.index写法ok,但是用类的写法就不支持么? #15
Comments
@jacksky007 thanks! |
hi @jacksky007 controller层按下面的写法,那router.js如何写呢? const Controller = require('egg').Controller
module.exports = class homeController extends Controller {
* index() {
yield this.ctx.render('index/index.js', this.ctx);
}
}; 这样写找不到路由,直接404了 const controller = app.controller
app.get('/', controller.home.home.index) router.js文件中this.ctx是一个空对象,拿不到homeController 我的目的就是想跟controller调用Service中的方法一样(ctx.service.biz.user)ctx.controller.xx.xx |
@jacksky007 嗯,是的,确实在router.js拿不到context,看来只看按文档方式做了,感谢感谢! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// exports.index写法ok
// exports.index = function* (ctx) {
// yield ctx.render('index/index.js');
// };
// class写法不ok
module.exports = app => {
class homeController extends app.Controller {
* index() {
console.log('app=====', app)
yield this.ctx.render('index/index.js', this.ctx);
}
}
return homeController;
};
The text was updated successfully, but these errors were encountered: