[英]Confusing es6 import -> export statement
Is this valid javascript? 这是有效的JavaScript吗? It does not error, and appears to work.
它没有错误,并且似乎可以正常工作。
export {default as Chooser} from "./chooser";
My interpretation is: 我的解释是:
import
the default
from "./chooser"
"./chooser"
import
default
export
the result from #1 as Chooser
export
#1的结果export
as Chooser
Is this what is happening? 这是怎么回事吗?
Is this valid JavaScript?
这是有效的JavaScript吗?
Yes. 是。
Is this what is happening?
这是怎么回事吗?
Yes. 是。
Your interpretation is correct. 您的解释是正确的。
import
thedefault
from"./chooser"
从
"./chooser"
import
default
This is correct. 这是对的。 The default thing being exported is
Chooser
and on import, you must use the name given to it with as ...
: 导出的默认值是
Chooser
并且在导入时, 必须使用为其指定的名称as ...
:
import { Chooser } from "./chooser";
export
the result from #1 asChooser
export
#1的结果export
为Chooser
This is also correct. 这也是正确的。 The name
Chooser
is giving the default a new name and exporting it. 选择
Chooser
名称为默认名称提供一个新名称并导出它。
Let me break this down: 让我分解一下:
export {
default as Chooser
} from "./chooser";
What this does is specify the file from which it is exported, and default as Chooser
exports the default under the name Chooser
. 这样做是指定从中导出的文件,
default as Chooser
出口的名义下的默认Chooser
。 Now, on import: 现在,在导入时:
import { Chooser } from "./chooser";
You must specify Chooser
to import because you've essentially named the default. 您必须指定要导入的
Chooser
,因为您已实质上将其命名为默认名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.