react首页项目要过多的import怎么办啊

新手上路,请多包涵

clipboard.png
如此,项目比较大,所有的组件都需要这样引入吗,有没有什么好的方法?

阅读 2.4k
1 个回答

有一个小小的优化,可以在组件文件夹里设置一个通用出口,比如在 statistic 文件夹下增加 index.js:

import Overview from './overview'
import AgentStatistic from './agentStatistic'
// ...

export {
  Overview,
  AgentStatistic,
  // ...
}

在这个文件中使用:

import {
  Overview,
  AgentStatistic,
  // ...
} from './statistic'

或者 import * as CUSTOM_NAME from './statistic',使用时,用 CUSTOM_NAME.overview 这种方式
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题