ES6 import in for-of-loop

前端 未结 3 1234
滥情空心
滥情空心 2021-01-17 12:53

Is there any way to import and export multiple files using for-of-loop (or another loop) in ES6?

const moduleNames = [\'NumberUtils\', \'StringUtils\', \'Arr         


        
3条回答
  •  余生分开走
    2021-01-17 12:57

    I think that better and more clear way to do it is to create an index file and then import multiple components in one import.

    //index.js
    import PopUp from './PopUp';
    import ToggleSwitch from './ToggleSwitch';
    
    export {
      PopUp,
      ToggleSwitch
    };
    
    //app.js
    
    import { PopUp, ToggleSwitch } from './components';
    

提交回复
热议问题