react 导出多个公共组件

components下有多个公共组件,想实现在components下创建一个index.ts,然后将components下的组件全部引入 通过export导出,这样在引用公共组件的时候就可以按需引入,import {xx,xx} from '@/comonents' index应该怎么写呢

阅读 8.2k
3 个回答

import { xx, xx1 } from '@/comonents'
对应的导出语句是:

export const xx = () => {};
export const xx1 = () => {};

当然,对于你的需求,想达到最小改动的话,index.js 可以这样写:

import xx from 'path/to/xx';
import xx1 from 'path/to/xx1';
export default { xx, xx1 };

在components文件夹下建立 index.ts 引入并导出组件 即可

export { default as Sider} from './Sider';
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题