【发布时间】:2018-04-10 02:06:09
【问题描述】:
索引.html
<html>
<head>
<script type="module">
import {answer} from './code.js'
console.info("It's ${answer()} time!")
</script>
</head>
<body>
</body>
</html>
code.js
export function answer(){
return 'module';
}
错误:从源“null”访问“file:///C:*******/es6/code.js”处的脚本已被 CORS 策略阻止:响应无效。因此不允许访问 Origin 'null'。
Chrome 说它可以支持模块,并且我已经看到了在网络上运行的示例,但是当我将它们复制下载并在本地运行它们时,我总是收到上述错误。我不想使用 Babel、Webpack 等。
我已尝试在 Chrome 和 Chrome Canary 中启用 Experimental Web Platform features 标志。
【问题讨论】:
标签: javascript google-chrome module ecmascript-6 same-origin-policy