有什么方法可以在ES6中使用回路(或其他回路)导入和导出多个文件?ES6在回路中导入
const moduleNames = ['NumberUtils', 'StringUtils', 'ArrayUtils', 'MyModule', 'AnotherModule', 'BaseModule']
let modules = {}
for (const moduleName of moduleNames) {
import module from './' + moduleName
modules.moduleName = module
}
export modules
没有环路我必须写:
import NumberUtils from './NumberUtils'
import StringUtils from './StringUtils'
import ArrayUtils from './ArrayUtils'
import MyModule from './MyModule'
import AnotherModule from './AnotherModule'
import BaseModule from './BaseModule'
export {
NumberUtils,
StringUtils
ArrayUtils
MyModule
AnotherModule
BaseModule
}
你可以做'从“./NumberUtils”出口{默认为NumberUtils};'仅供参考,这使得这些类型的列表更容易保持。为什么添加一行代码比向数组添加项目更困难? – loganfsmyth