简体   繁体   English

从索引文件中导出组件

[英]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.

相关问题 如何从 React 中的索引文件导出多个组件? - How to export multiple components from an index file in React? 将所有组件导出到 index.js 文件中是不好的做法吗? - Is it bad practice to export all components into an index.js file? 无法从ReactJS中的一个JS文件导出2个高阶组件 - Unable to export 2 Higher Order Components from one JS file in ReactJS 如何导出 index.js 中的所有组件? - How to export all components in index.js? 如何在 React Components 中将默认文件从索引更改为自定义文件? - How to to change the default file from index to a custom in React Components? 如何在一个文件中导出样式组件? - How to export Styled Components in one file? 如何在index.js中动态导出组件? - How can I dynamically export components in index.js? 样式化从索引文件导入的 React 组件时出错,但直接从组件文件导入时出错 - Error when styling React components imported from index file, but not when importing directly from component file 导出Webpack捆绑文件中的所有react组件并在html文件中使用 - Export all react components in Webpack bundle file and use in html file 如何在一个index.html文件中加载来自不同文件夹的多个angular2组件? - How to Load multiple angular2 components from different folders in one index.html file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM