【发布时间】:2019-03-27 16:04:51
【问题描述】:
我有一个 ES6 模块 (mymodule) 和 HTML 页面,其中包含用户打开页面时必须执行的 JS 代码。这是我的模块:
//mymodule.js
class TestClass {
getString() {
return "TestString";
}
}
export {TestClass}
这是我的页面:
//page.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Page</title>
<script src="./mymodule.js" type="module"></script>
</head>
<body>
<h1>Hello World!</h1>
<script type="module">
import {TestClass} from "./mymodule";
let test = new TestClass();
console.log("OUTPUT: " + test.getString());
</script>
</body>
</html>
Page.html 和 mymodule.js 在同一个文件夹中,但是,当我在浏览器中打开 page.html 时,控制台上什么都没有(没有错误,没有输出) - 我使用的是 FF 62.0.3。如何解决?
【问题讨论】:
标签: javascript html