在我的本机反应应用程序中,我目前有一个用户类,我在其中定义了一个当前用户,如下所示:
class User {
static currentUser = null;
//other relevant code here
static getCurrentUser() {
return currentUser;
}
}
export default User;
在另一个类中,我试图访问此 currentUser 的设置值。我不知道如何正确调用这个函数;我收到错误 User.getCurrentUser is not a function
。我应该以不同的方式调用这个函数吗?
var User = require('./User');
getInitialState: function() {
var user = User.getCurrentUser();
return {
user: user
};
},
原文由 user3802348 发布,翻译遵循 CC BY-SA 4.0 许可协议
您正在混合
import
/export
样式。您应该将导入更改为或者
或者改变你的出口: