在React应用程序中,我尝试将某些业务逻辑封装在称为Authentication的类中。当我尝试在Authentication类上调用名为configure的方法时,出现以下错误:
TypeError:WEBPACK_IMPORTED_MODULE_5__authentication_js .a.configure不是函数
在我的React app.js文件中,我使用以下命令导入身份验证类:
import Authentication from './authentication.js';
然后尝试在构造函数中按如下方式访问它:
constructor(props) {
super(props);
Authentication.configure();
}
authentication.js的代码如下:
class Authentication {
constructor(props) {
console.log('inside constructor of Authentication class');
}
configure(){
//some setup logic, still fails if I comment it all out
}
}
export default Authentication;
我不确定如何解决此问题。我知道在未对内部方法调用bind方法之前,我已经在react中看到过类似的问题,但是我不确定外部类的公共方法是否需要它,是否需要,我我不确定如何实施。任何帮助/指导将不胜感激。
configure
是Authentication
该类的实例方法。
要么使configure
静态的,或者导出实例的Authentication
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句