【发布时间】:2018-04-11 07:55:15
【问题描述】:
我正在尝试使用动态导入 - import()
我读过这个dynamic-import documentations 并观看了chrome devtools video,
仍然找不到正确的方法。
错误:
Uncaught (in promise) ReferenceError: module is not defined
样板文件:
我创建了一个新项目。
没有 webpack,没有任务运行器。
只需运行带有 http-server 节点包的服务器,这些文件包含这些文件:
- index.html
- index.js
- a.js
index.html:
<button id="btn"> Lazy load a module</button>
<script src="index.js"></script>
index.js:
const btn = document.querySelector('#btn');
btn.addEventListener('click', event => {
import('./a.js').then(module => { console.log(module) })
});
a.js
module.exports = { type: 'LazyModule'}
我在这里错过了什么?
【问题讨论】:
标签: javascript html dynamic-import