出于某种原因,当我执行 var sphere = new Core(); 时在游戏中,我看到核心未定义,即使我导入它:
Game.js
import Core from 'gameUnits/Core'
export class Game {
constructor() {
Core.js:
export class Core {
constructor(scene) {
}
}
当您在没有大括号的情况下进行导入时,您正在尝试导入default模块的对象。
所以,你必须添加default
关键字到您的Core
出口:
export default class Core {
constructor(scene) {
}
}
OR放置你的Core
导入到大括号中:
import { Core } from 'gameUnits/Core';
Look here http://www.2ality.com/2014/09/es6-modules-final.html有关 ECMAScript 6 模块的更多信息
PS: Using default
您可以为其指定任何名称的关键字Core
班级。例如:
import GameUnitsCore from 'gameUnits/Core';
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)