1.分别暴露

m1.js

  1. export function teach(){
  2. console.log('hello')
  3. }

index.html 通用方式

  1. <scritp type="module">
  2. import * as m1 form "./src/js/m1.js"
  3. </scritp>

index.html 结构赋值

  1. <scritp type="module">
  2. import {name,teach} form"./src/js/m1.js"
  3. </scritp>

2.统一暴露

m2.js

  1. let name="Nihao"
  2. function teach(){
  3. console.log('hello')
  4. }
  5. export{
  6. name,teach
  7. }

index.html 通用方式

  1. <scritp type="module">
  2. import * as m2 form "./src/js/m2.js"
  3. </scritp>

index.html 结构赋值

  1. <scritp type="module">
  2. import {name,teach} form"./src/js/m2.js"
  3. </scritp>

3.默认暴露

tips:对象形式
m3.js

  1. export default{
  2. name:"jikey",
  3. go:{
  4. console.log('hello')
  5. }
  6. }

index.html

  1. <scritp type="module">
  2. import * as m3 from "./src/js/m3.js"
  3. </scritp>

index.html 结构赋值

  1. <scritp type="module">
  2. import {default as m3} from"./src/js/m3.js"
  3. </scritp>

index.html 简便方式 针对默认暴露

  1. <scritp type="module">
  2. import m3 from"./src/js/m3.js"
  3. </scritp>

4.当重名时取别名

  1. <scritp type="module">
  2. import {name as age,teach} from"./src/js/m2.js"
  3. </scritp>