在ES6中,使用export default 和 export 向外暴露成员
export default
export default 向外暴露的成员,可以使用任意变量来接收
export default 向外暴露成员

或

main.ts 接收 test.ts使用export default 向外暴露的成员

控制台输出

在一个模块中,export default 只允许向外暴露一次
export
使用export导出的成员,必须严格按照导出时候的名称,来使用{ }按需接收
export向外暴露的成员

使用export向外暴露的成员,只能使用{ }的形式来接收,这种形式,叫做【按需接收】

控制台输出

export可以向外暴露多个成员,同时,如果某些成员,在import导入时,不需要,可以不在{ }中定义
export向外暴露多个成员

或

不需要的成员,可以不在{ }中定义

控制台输出

使用export导出的成员,如果想换个变量名称接收,可以使用as来起别名

3、在一个模块中,可以同时使用export default 和export 向外暴露成员
export default 和export 向外暴露成员

在main.js中接收,test.js使用export default 和 export 向外暴露的成员

使用export向外暴露的成员,只能使用{ }的形式来接收,这种形式,叫做【按需导出】
网友评论