【ES6】ESModual
什麼樣的匯出對應什麼樣的匯入
預設匯入(只能有一個)
常見的匯出方式,通常用於匯出物件,在 React 開發中可用來匯出元件
/** 匯出頁 exportDefault.js */
export default function fn(){
console.log("default export")
}
/** 匯入 index.html */
/** export ${name}(隨便取) from ${path} */
<script type="module">
export aa from "./exportDefault.js";
aa();
</script>
/** 匯出頁 exportDefault.js */
export default {
name: "sam",
func: function(){
console.log("預設方法...")
}
}
/** 匯入 index.html */
/** export ${name}(隨便取) from ${path} */
<script type="module">
export aa from "./exportDefault.js";
console.log(aa.name);
console.log(aa.func());
</script>
具名匯入(可多個)
