本文介绍了JavaScript中“export”和“export default”的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
两者之间有什么区别?我看到人们使用:
What exactly is the difference between the two? I've seen people use:
function foo () {
...
}
export default foo;
我看过:
function bar () {
...
}
export bar;
另外,为什么要使用另一个?
Also, why would you use the one over the other?
推荐答案
如果您需要使用命名导出导出多个对象(没有默认关键字)。
If your need is to export multiple objects go with named exports(without default keyword).
function x1(){};
function x2(){};
export {x1},{x2}; //my-module.js
import {x1},{x2} from 'my-module';
否则单一导出,默认导出工作良好
otherwise for a single export, default export works well
export default function x1() {};
import x1 from 'my-module';
这篇关于JavaScript中“export”和“export default”的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!