[英]export components from index file
i have shared components folder when i created some components and i want to export all of them to index.js file and then export all of them from that file.当我创建一些组件时,我有共享组件文件夹,我想将它们全部导出到 index.js 文件,然后从该文件中导出所有组件。 thats how it looks from one of the components file:
这就是它从一个组件文件中的外观:
export default ToggleSwitch;
now in the index file i try to export them again, it looks like this:现在在索引文件中我尝试再次导出它们,它看起来像这样:
export { default as ToggleSwitch } from './ToggleSwitch'; export { default as Input } from './TextField'; export { default as Button } from './Button';
when i try to import one of the components if i import like this:当我尝试导入其中一个组件时,如果我像这样导入:
import Button from '../../shared/components';
i get this error saying that '../../shared/components' does not contain a default export我收到此错误消息,说“../../shared/components”不包含默认导出
and when i try to import it like this,当我尝试像这样导入它时,
import { Button } from '../../shared/components';
i get error saying Button is not exported from '../../shared/components'.我收到错误消息说 Button 未从“../../shared/components”导出。
what am i doing wrong here?我在这里做错了什么?
Have you tried importing as import { Button } from 'shared/components';
您是否尝试过从
import { Button } from 'shared/components';
? ?
For reference, the current codebase I work with has a similar structure for stores (flux stores) and this pattern works.作为参考,我使用的当前代码库具有类似的存储结构(通量存储),并且这种模式有效。
An example from the codebase: import { ClickStore } from 'stores';
代码库中的一个示例:
import { ClickStore } from 'stores';
. .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.