ES6学习:export、export default的使用方法

在es6中使用export、和export default向外暴露成员;
使用 import 模块名称 from “模块标示符” 来接收成员;
import *** from *** 是ES6中导入模块的方式。

export、export default在使用上的区别:

  1. 使用export default向外暴露的成员,可以用任意变量接收
  2. 在一个模块中,可以同时使用export default 和export 向外暴露成员;export default 只允许向外暴露一次
  3. 使用export向外暴露的成员,必须用{ }接收,变量之间用逗号分隔;且名称必须与导出时的名称一致;如果想要换变量接收,可以使用as来起别名 import {content as content1} from ***
  4. export可以向外暴露多个成员,如果某些成员,在import导入时,不需要,可以不在{ }中定义

猜你喜欢

转载自blog.csdn.net/weixin_45559449/article/details/102552373