模塊操作一
temp.js
export var a='eternity';
index.js 跟temp.js同路徑
import {a} from ./temp;
模塊操作二
temp.js
export var a='eternity';
export var aa='zhang';
export function add(a,b){
return a+b;
}
index.js 跟temp.js同路徑
import {a,aa,add} from ./temp;
模塊操作三
temp.js
var a='eternity';
var aa='zhang';
export {
name as a,
cname as aa
};
index.js 跟temp.js同路徑
import {name,cname} from ./temp;
模塊操作四
temp.js
export default var b='zhang';
index.js 跟temp.js同路徑
import b from ./temp;
或者
import name from ./temp;
解釋說明
1.使用export輸出,import匯入的時候必須加{},同時名字必須是export時的名字
2.使用export default輸出,import匯入不用加{},同時名字可以自定義
3.匯入的來源檔案默認帶.js,可以不用再加后綴名,也可以加上名字,例如import b from ./temp.js;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/31032.html
標籤:其他
上一篇:es6物件
