版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010476739/article/details/81584926
参照:http://es6.ruanyifeng.com/#docs/module-loader
注意:最新版本的chrome浏览器已支持module语法,需要在web服务器环境下运行!
设置浏览器启用es6语法功能:
1.在浏览器的url中输入:chrome://flags/
设置下面选项为enable,重启浏览器。
准备代码:
2.index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="module" src="module1.js"></script>
<script>
</script>
</head>
<body>
</body>
</html>
3.module1.js
import {show} from './module2.js';
show();
4.module2.js
export function show(){
i++;
console.log(i);
}
var i=0;
在浏览器端打开调试:
扫描二维码关注公众号,回复:
4333045 查看本文章
ok!