目录
- folder
- index.html
- index.js
- index1.jsindex.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运行一样。
发布于 2019-12-18 07:09:31
将脚本导入为module:File应导出为module.exports
有关工作示例,请参阅下面的链接:https://stackblitz.com/edit/js-mgwfrd
https://stackoverflow.com/questions/59386512
复制相似问题