[英]Can we use `export default` and `module.exports` at same time?
How to use export default
and module.exports
in the same file. 如何在同一文件中使用
export default
和module.exports
。
/******** Exports ********/ / ********出口******** /
export default function () { ... };
module.exports = {
A,
B,
C
};
How to import them? 如何导入?
Pretty sure it's not possible - a default export is basically the same thing as the object (or other expression) you assign to module.exports
. 可以肯定,这是不可能的-默认导出与您分配给
module.exports
的对象(或其他表达式)基本相同。 Better to use just one syntax style ( module.exports
or export
) consistently. 最好始终使用一种语法样式(
module.exports
或export
)。 If you're looking to export a default and export other things as well, consider using named exports instead, with export
syntax: 如果您要导出默认值并也导出其他内容,请考虑使用具有
export
语法的命名export
:
// define A, B, C
export default function() { ... };
export { A, B, C };
and import with, for example 并导入,例如
import fn, { A } from './module';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.