从子目录导出默认值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从子目录导出默认值相关的知识,希望对你有一定的参考价值。

假设我有一个看起来像这样的文件结构

–Directory
--myComponent.js
––Subdirectory
–––fileA.js
–––fileB.js
–––index.js
––index.js

我的Directory/Subdirectory/index.js看起来像这样:

export { default as fileA } from './fileA';
export { default as fileB } from './fileB';

我的Directory/index.js看起来像这样:

export { default as myComponent } from './myComponent';
import * as _Subdirectory from './Subdirectory';
export const Subdirectory = _Subdirectory;

我的问题 - 来自Directory/index.js的第2行和第3行可以写成一行(就像第1行一样)?

答案

是的,你可以组合这些线:

export { default as Subdirectory } from "./Subdirectory";

以上是关于从子目录导出默认值的主要内容,如果未能解决你的问题,请参考以下文章