JavaScript Module
浏览器加载 ES6 模块,也使用<script>标签,但是要加入type="module"属性。
<script type="module" src="./foo.js"></script>
异步加载
<script type="module" src="./foo.js" async></script>
import命令
ES6 模块也允许内嵌在网页中,语法行为与加载外部脚本完全一致。
<script type="module"> import utils from "./utils.js"; </script>
export 命令
// 写法一
export var m = 1;
// 写法二
var m = 1;
export { m };
// 写法三
var n = 1;
export { n as m };
// 写法四
export function f() { };
// 写法五
function f() { }
export { f };

浙公网安备 33010602011771号