我们可以同时使用`export default`和`module.exports`吗?

问题描述 投票:0回答:1

如何在同一个文件中使用export defaultmodule.exports

/ ********导出******** /

export default function () { ... };

module.exports = {
    A,
    B,
    C
};

如何导入它们?

javascript react-native
1个回答
2
投票

非常确定它是不可能的 - 默认导出与您分配给module.exports的对象(或其他表达式)基本相同。最好只使用一种语法风格(module.exportsexport)。如果您要导出默认值并导出其他内容,请考虑使用命名导出,使用export语法:

// define A, B, C
export default function() { ... };
export { A, B, C };

和导入,例如

import fn, { A } from './module';
© www.soinside.com 2019 - 2024. All rights reserved.