I believe many people have used export, export default, import, but what is the difference between them?
In JavaScript ES6, export and export default can be used for exporting constants, functions, files, modules, etc., which you can import in other files or modules in such a way that they can be import+(常量 | 函数 | 文件 | 模块)名
used, but in a file or module, Export, import can have multiple, export default only one.
Specific use:
1.
//demo1.jsexport const str = ‘hello world‘export function f(a){ return a+1}
The corresponding import method:
//demo2.jsimport { str, f } from ‘demo1‘ //也可以分开写两次,导入的时候带花括号
2.
//demo1.jsexport default const str = ‘hello world‘
The corresponding import method:
//demo2.jsimport str from ‘demo1‘ //导入的时候没有花括号
原文地址http://blog.csdn.net/zhou_xiao_cheng/article/details/52759632
The difference between export and export default in JavaScript ES6