Egg 中不同模块的 this 属性
🌙
手机阅读
本文目录结构
场景
研究 Egg 项目的不同场景下,不同模块的 this 里都有什么属性
准备工作
搭建Egg项目,参照 Egg快速初始化
不同模块的代码
controller
代码如下
'use strict';
const Controller = require('egg').Controller;
class HomeController extends Controller {
async index() {
const { ctx } = this;
console.log('Anbang 测试 app/controller 下的this: ', Object.keys(this));
ctx.body = 'hi, egg';
}
}
module.exports = HomeController;
输出结果如下
Anbang 测试 app/controller 下的this: [ 'ctx', 'app', 'config', 'service' ]
这里主要有