components下有多个公共组件,想实现在components下创建一个index.ts,然后将components下的组件全部引入 通过export导出,这样在引用公共组件的时候就可以按需引入,import {xx,xx} from '@/comonents' index应该怎么写呢
components下有多个公共组件,想实现在components下创建一个index.ts,然后将components下的组件全部引入 通过export导出,这样在引用公共组件的时候就可以按需引入,import {xx,xx} from '@/comonents' index应该怎么写呢
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 };
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答5.1k 阅读✓ 已解决
3 回答1.8k 阅读✓ 已解决
这个应该是你要的效果
https://codesandbox.io/s/stoi...