export
点击查看代码
// m1.js
//分别暴露
export let school = "XX学校";
export function teach() {
console.log("教学");
}
// m2.js
// 统一暴露
let school = "XX学校";
function findJob() {
console.log("找工作");
}
export { school, findJob };
// m3.js
// 默认暴露
export default {
school: "XXX学校",
change: function () {
console.log("改变你");
}
}
import
点击查看代码
// 1、通用的导入方式
// 引入 m1.js 模块内容
import * as m1 from './m1.js'
// 引入 m2.js 模块内容
import * as m2 from './m2.js'
// 引入 m3.js 模块内容
import * as m3 from './m3.js'
// 2、解构赋值的形式导入
import { school, teach } from './m1.js'
import { school as jobSchool, findJob } from './m2.js'
import { default as m3 } from './m3.js'
// 3、简便形式 针对默认暴露
import m3 from './m3.js'