暴露模块
分别暴露形式 m1.js
export const a = 1;
export function fn() {
console.log(1)
}
统一暴露形式 m2.js
const a = 1;
function fn() {
console.log(1)
}
export {
a,
fn
}
默认暴露形式 m3.js
export default {
a: 1,
fn() {
console.log(1)
}
}
引入模块
<script type="module">
// 1. 通用引入方式
import * as m1 from "./m1.js"
import * as m2 from "./m2.js"
import * as m3 from "./m3.js"
// 2. 解构赋值形式
import { a, fn } from "./m1.js"
import { a as m2_a, fn as m2_fn } from "./m2.js"
import { default as m3 } from "./m3.js"
// 3. 简便形式,只针对于默认暴露形式!!!
import a from "./m3.js"
</script>
Test
测试