Is it possible to import modules from all files in a directory, using a wildcard?

前端 未结 13 2304
陌清茗
陌清茗 2020-11-22 04:25

With ES6, I can import several exports from a file like this:

import {ThingA, ThingB, ThingC} from \'lib/things\';

However, I like the orga

13条回答
  •  面向向阳花
    2020-11-22 04:34

    This is not exactly what you asked for but, with this method I can Iterate throught componentsList in my other files and use function such as componentsList.map(...) which I find pretty usefull !

    import StepOne from './StepOne';
    import StepTwo from './StepTwo';
    import StepThree from './StepThree';
    import StepFour from './StepFour';
    import StepFive from './StepFive';
    import StepSix from './StepSix';
    import StepSeven from './StepSeven';
    import StepEight from './StepEight';
    
    const componentsList= () => [
      { component: StepOne(), key: 'step1' },
      { component: StepTwo(), key: 'step2' },
      { component: StepThree(), key: 'step3' },
      { component: StepFour(), key: 'step4' },
      { component: StepFive(), key: 'step5' },
      { component: StepSix(), key: 'step6' },
      { component: StepSeven(), key: 'step7' },
      { component: StepEight(), key: 'step8' }
    ];
    
    export default componentsList;
    

提交回复
热议问题