1.多行暴露
导出
// a.js 文件
export function a1() {
console.log('a1');
}
export function a2() {
console.log('a2');
}
导入
// index.js 文件
import {a1, a2} from './a.js'
2.统一暴露
导出
// b.js 文件
function b1() {
console.log('b1');
}
function b2() {
console.log('b2');
}
export {b1, b2}
导入
// index.js 文件
import {b1, b2} from './b.js'
3.默认暴露
导出
// c.js 文件
export default function () {
console.log('c');
}
导入
// index.js 文件
import c from './c.js'
注意:
- 多行暴露、统一暴露,在主文件 index.js 中引入时,必须使用对象的解构赋值引用
- 默认暴露,直接引入即可