【发布时间】:2020-04-10 16:20:19
【问题描述】:
目录
- folder
- index.html
- index.js
- index1.js
index.html
<!-- main content --->
<script type='module' src='./index.js'></script>
index.js
import {show} from "./index1"
show();
index1.js
export default function show(){
console.log('hello world');
}
说明
在浏览器上运行 index.html 时,它不起作用,我得到了这个错误:
Access to script at 'file:///Users/xxx/Documents/code/canvas/test/index.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
它可以与服务器一起工作,如何使它在没有服务器的情况下工作,多模块。
从其他导入一个模块。就像使用 nodejs env 运行一样。
【问题讨论】:
标签: javascript ecmascript-6 module