在代码导入中未定义es6 import var [英] es6 import var not defined in code importing
本文介绍了在代码导入中未定义es6 import var的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Game.js
import'from'gameUnits / Core'
export class Game {
constructor(){
Core.js:
export class Core {
构造函数(场景){
}
}
解决方案>
$ b $来自gameUnits / Core的b
当您导入没有大括号时,您尝试导入模块的默认对象。
所以,您必须添加Core 导出默认类Core {
构造函数(场景){
}
}
或将您的 Core
导入大括号:
$ b $来自gameUnits / Core的b
import {Core};
查看这里了解更多关于ECMAScript 6模块的信息
PS :使用 default
关键字,您可以为 Core
类指定ANY名称。例如:
从gameUnits / Core导入GameUnitsCore;
For some reason when I do var sphere = new Core(); in Game, I see Core is undefined, even though I import it:
Game.js
import Core from 'gameUnits/Core'
export class Game {
constructor() {
Core.js:
export class Core {
constructor(scene) {
}
}
解决方案
When you make import without curly brackets you're trying to import default object of the module.
So, you must add default
keyword to your Core
exporting:
export default class Core {
constructor(scene) {
}
}
OR place your Core
importing into curly brackets:
import { Core } from 'gameUnits/Core';
Look here for more informaction about ECMAScript 6 modules
PS: Using default
keyword you can specify ANY name for Core
class. For example:
import GameUnitsCore from 'gameUnits/Core';
这篇关于在代码导入中未定义es6 import var的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文