chrome瀏覽器啟用es6語法支援,初次體驗瀏覽器端模組化載入
阿新 • • 發佈:2018-12-02
參照: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;
在瀏覽器端開啟除錯:
ok!