1 //test.mjs
 2 export default function () {
 3     console.log('foo');
 4 }
 5 
 6 export var a1 = "aaaaaaaaaa"
 7 
 8 export var b1 = "bbbbbbbbbb"  
 1 //main.mjs
 2 import xxx from './test.mjs'
 3 //不指定的情况下,xxx是默认的default模块
 4 console.log(xxx())
 5 console.log('-----------------------------------')
 6 
 7 //导入默认值和其他变量
 8 import {default as yyy,a1,b1} from './test.mjs'
 9 console.log(yyy,a1,b1)
10 console.log('-----------------------------------')
11 
12 //导入*,里面包括default
13 import * as vvv from './test.mjs'
14 console.log(vvv,vvv.a1,vvv.b1,vvv.default)
15 console.log('-----------------------------------')
16 console.log((vvv.default)()) //可以调用函数
17 console.log(vvv.default()) //也可以调用函数

 

posted on 2022-12-09 20:13  qqhfeng16  阅读(18)  评论(0编辑  收藏  举报