如何重新导出另一个模块的默认导出? [英] How to re-export another module's default export?
本文介绍了如何重新导出另一个模块的默认导出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想按以下方式导出某些模块,但始终失败.
I want to export some module like below way but always failed..
foo.js
const foo = {
a: 'b'
};
export default foo;
index.js
export foo from './foo'; // encounter error here
export * from './foo'; // it works..
我不知道为什么不能使用第一种方法从foo.js
导出模块,我认为我可以导出诸如func,类,变量等之类的东西.
I don't know why can't I use the first method to export module from foo.js
, in my opinion, I can export anything like func, class, variables etc..
推荐答案
要将一个模块的默认导出导出为另一个模块的命名导出,您必须执行以下操作:
To export a default export of one module as a named export of another you must do:
// index.js
export { default as foo } from './foo';
您现在可以将foo
作为命名导出导入其他地方:
You can now import foo
as a named export elsewhere:
// another.js
import { foo } from './index'
这篇关于如何重新导出另一个模块的默认导出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文