我有moduleA导出一些函数:
// moduleA.js
export function f1() {...}
export function f2() {...}
有没有办法在moduleB中重新导出moduleA的所有导出,并使其看起来像一个对象:
// moduleB.js
export * as a from 'moduleA'; // pseudo code, doesn't work
这样我才能以这种方式使用它?
// main.js
import {a} from 'moduleB';
a.f1();
a.f2();
答案 0 :(得分:23)
答案 1 :(得分:-1)
<强> file1.js 强>
export let uselessObject = {
con1 : function () {
console.log('from file1.js')
}
}
<强> file2.js 强>
import { uselessObject } from './file1.js'
uselessObject.con2 = function(){
console.log('from file2.js ')
}
export { uselessObject } from './file1.js'
<强> Index.js 强>
import { uselessObject } from './file2.js'
uselessObject.con1()
uselessObject.con2()
<强>输出强>
from file1.js
from file2.js