[英]What is the difference between these ES6 import statements?
import { A, B, C } from 'somecomponent/components'
import { A } from "somecomponent/components/A";
import { B } from "somecomponent/components/B";
import { C } from "somecomponent/components/C";
Does both the import statements above and below import only A, B, C?上面和下面的导入语句是否都只导入 A、B、C? Is there any difference between these statements?
这些陈述之间有什么区别吗? Is there a preference to use either of them?
是否有偏好使用它们中的任何一个?
Yes, both imports do import A
, B
and C
into the current module.是的,两个导入都将
A
、 B
和C
导入当前模块。 However, the first imports them from one module, the second imports them from three different modules - which might have different values.但是,第一个从一个模块导入它们,第二个从三个不同的模块导入它们——它们可能具有不同的值。
The two ways are only equivalent if - and only if - the module at 'somecomponent/components'
does这两种方式只有在 - 且仅当 -
'somecomponent/components'
的模块
export { A } from "somecomponent/components/A";
export { B } from "somecomponent/components/B";
export { C } from "somecomponent/components/C";
(and iff these resolve to the same modules). (如果这些解析为相同的模块)。
There is no difference whatsoever.没有任何区别。 And yes, only
A
, B
, and C
are visible to you.是的,您只能看到
A
、 B
和C
。
As for preference... whatever you like.至于偏好……随便你。 Myself, less typing is better.
我自己,打字越少越好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.