我是 ES6 (ECMAScript 6)的新手,我想在浏览器中使用它的 模块系统。我读到 ES6 受 Firefox 和 Chrome 支持,但使用 export
Uncaught SyntaxError: Unexpected token import
我有一个 test.html 文件
<html>
<script src="test.js"></script>
<body>
</body>
</html>
和一个 test.js 文件
'use strict';
class Test {
static hello() {
console.log("hello world");
}
}
export Test;
为什么?
原文由 cdarwin 发布,翻译遵循 CC BY-SA 4.0 许可协议
许多现代浏览器现在都支持 ES6 模块。只要您使用
<script type="module" src="...">
导入脚本(包括应用程序的入口点),它就可以工作。查看 caniuse.com 了解更多详情: https ://caniuse.com/#feat=es6-module