The original address of this article link: http://blog.csdn.net/zhou_xiao_cheng/article/details/52759632, not allowed to reprint without Bo master.
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.
You can import it in other files or modules to be able to use it, import+(常量 | 函数 | 文件 | 模块)名
but in a file or module, there can be multiple export, import, and 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‘ //导入的时候没有花括号
The difference between export and export default in JavaScript ES6