假设我有一些这样的代码:
module.exports = {
Someclass: require('./lib/Someclass')
}
我可以让它更ES6
export default {
Someclass: require('./lib/Someclass')
}
但是我如何在不设置变量的情况下用 es6 语法替换 require 呢? 提前致谢
最佳答案
您可能不应该默认导出对象,而应使用命名导出。所以要么
// re-export the whole namespace
import * as Someclass from './lib/Someclass';
export { Someclass }
或
// re-export the default export
export { default as Someclass } from './lib/Someclass';
关于JavaScript 导入而不是对象中的 require,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61477918/