多个 export 的变量如何一次性 import

349 阅读1分钟

需求

// A 文件
export function a(){}
export function b(){}
export function c(){}
...
// B 文件
import x from './A.js'

在 A 文件中 export 了一堆 function,我们期望在 B 中一次性引入进来。

方案

有两种方案

方案1

// A
export function a(){}
export function b(){}
export function c(){}
...
// B
import * as x from './A.js'

方案2

// A
function a(){}
function b(){}
function c(){}
...
export default {a,b,c}
// B
import x from './A.js'