ES模块化的导入和导出
1index页面中
//注意type='modle'
//注意type='modle'
<script src='aaa.js' type='modle'></script>
2.aaa.js中导出
export指令用于导出变量
//aaa.js
//方式1,命名时直接导出
export let name ='chen';
export let age = 22;
export let height =1.82;
//方式2,最后导出
let name ='chen';
let age = 22;
let height =1.82;
export(name,age,height)
函数和类也一样可以导出
3.bbb.js中导入
(1)
import {name,age,height} from "./aaa.js"
import{test,Person} from "./aaa.js"
(2)如果要全部导入,和python差不多,可以自己取个别名,如:chenaaa
import * as chenaaa from "./aaa.js"
console.log(chenaaa.name)