- 带{}和不带{},其实就是命名导出和默认导出的区别。
- 例如有两个文件father.js,son.js
export default father = () => {}
export default father = () => {}
import father from './father.js;
import { son } from './son.js';
- 对于father引用方法,father.js文件中有默认的export defulat导出的方法,那么引用成功。
- 对于son引用方法,son.js中需要有同名的方法,这样就可成功导出引用。
import father from './father.js; // 生效
import father1 from './father.js;
import father2 from './father.js; // 生效
- 以上这三个文件总会解析到father.js中export defulat导出的方法。
import { son } from './son.js';
import { son1 } from './son.js';
import { son2 } from './son.js';
- 上面son1,son2解析不到son.js中的son方法,因为名字不一样,import带{}只导出命名模块。
- 注:一个模块中只能有一个export defulat默认导出,可以有多个默认导出。