【发布时间】:2018-09-13 09:06:26
【问题描述】:
我的 javascript 应用程序适用于自助服务终端,并且仅针对 Chrome 浏览器。我正在使用 Chrome 版本 65。我正在尝试使用 ES6 模块而不使用像 Babel 这样的转译器。我的代码原来是:
在 index.html 中:
<script src="js/index.js"></script>
index.js:
import Main from './classes/Main.js';
const init = () => {
const app = new Main();
};
init();
Main.js:
export default class Main {
constructor() {
}
}
最初我从 index.js 第 1 行收到错误“Uncaught SyntaxError: Unexpected identifier”。然后基于ES6 module Import giving "Uncaught SyntaxError: Unexpected identifier",我在 html 标签中添加了 'type="module"':
<script type="module" src="js/index.js"></script>
这确实加载了,但根据网络分析器,我的浏览器加载 index.js 和 main.js 大约需要 15 秒。会发生什么?
【问题讨论】:
标签: javascript es6-modules es6-class