问题发生在引入自定义模板
html内容:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
</html>
<script type="module">
import * as f1 from './project01.js';
console.log(f1.aaa);
</script>
js文件内容:
export let aaa = 'aaaaaa';
报错信息:
project03.html:1 Access to script at 'file:///D:/js/project01.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.
project01.js:1 Failed to load resource: net::ERR_FAILED
纠错方法:
虽然html和js文件都在同一目录下,但没有引入工程。显示路径错误。
.表示根目录。
纠错方法时将两个文件所在的文件夹(或称为目录)引入到编辑器中。