当前位置:网站首页>egg.js中Class constructor BaseContextClass cannot be invoked without ‘new‘解决方法

egg.js中Class constructor BaseContextClass cannot be invoked without ‘new‘解决方法

2022-08-10 00:26:00 抗争的小青年

错误翻译过来就是:没有’new’就无法调用类构造函数BaseContextClass

这个时候应该去看看函数是否写对,我的报错原因如下:

'use strict';


const Controller = require('egg').Controller;
+class mackController extends Controller() {
  async index() {
    const { ctx } = this;
    ctx.body = '<h1>I am Mack</h1>'
  }
}

module.exports = mackController

在继承Controller时,后面加了一个括号,把括号去掉便可正常运行。

'use strict';


const Controller = require('egg').Controller;
class mackController extends Controller {
    
  async index() {
    
    const {
     ctx } = this;
    ctx.body = '<h1>I am Mack</h1>'
  }
}

module.exports = mackController
原网站

版权声明
本文为[抗争的小青年]所创,转载请带上原文链接,感谢
https://blog.csdn.net/liyuchenii/article/details/126255673