前端小白一枚
这是index.html
<!DOCTYPE html>
<html language="en">
<head>
<meta charset="utf-8">
<!-- <meta http-equiv="X-UA-Compatible"> -->
<title>Document</title>
<script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
<script src="https://cdn.staticfile.org/vue-router/2.7.0/vue-router.min.js"></script>
<script src="https://unpkg.com/vuex"></script>
<style>
img:hover
{
cursor:pointer;
}
#btn {
display: block;
}
</style>
</head>
<body>
<script type="module">
import { myName, myAge, myfn } from "./js/exportDemo.js";
console.log(myfn());// My name is Tom! I'm 20 years old.
console.log(myAge);// 20
console.log(myName);// Tom
</script>
</body>
</html>
以下是exportDemo.js
let myName = "Tom";
let myAge = 20;
let myfn = function(){
return "My name is" + myName + "! I'm '" + myAge + "years old."
}
/*let myClass = class myClass {
static a = "yeah!";
}*/
export { myName, myAge, myfn }
通过以下路径访问index
file:///C:/Users/Abby/Desktop/test/index.html#/
FF运行没报错,Chrome解析报错了,报错信息如下:
Access to script at 'file:///C:/Users/Abby/Desktop/test/js/exportDemo.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.
index.html:23
GET file:///C:/Users/Abby/Desktop/test/js/exportDemo.js net::ERR_FAILED
不是说Chrome58以后就支持es6么?我的版本是74