<script src="aaa.js" type="module"></script>
<script src="./bbb.js" type="module"></script>
<script src="./mmm.js" type="module"></script>
通过默认浏览器运行时报错,加载js被阻止。出现了以下错误
Access to script at 'file:///E:/mystudy/VUE/day2/12-%E5%89%8D%E7%AB%AF%E6%A8%A1%E5%9D%97%E5%8C%96/02-es6%E7%9A%84%E6%A8%A1%E5%9D%97%E5%8C%96%E5%AE%9E%E7%8E%B0/aaa.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
index.html:16 GET file:///E:/mystudy/VUE/day2/12-%E5%89%8D%E7%AB%AF%E6%A8%A1%E5%9D%97%E5%8C%96/02-es6%E7%9A%84%E6%A8%A1%E5%9D%97%E5%8C%96%E5%AE%9E%E7%8E%B0/aaa.js net::ERR_FAILED
解决方法如下:
1. 下载安装 live server
2. 选择需要运行的文件,通过open with live server打开
3. 运行成功