为什么以及何时在es6模块中使用默认导出而不是命名导出? [英] Why and when to use default export over named exports in es6 Modules?
本文介绍了为什么以及何时在es6模块中使用默认导出而不是命名导出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在stackoverflow中提到了所有问题。
但是没有建议为什么以及何时使用默认导出。
I have referred all the questions in stackoverflow. But none of the suggested why and when to use default export.
我刚看到默认值可以提到当文件中只有一个导出时
I just saw that default can be metioned "When there is only one export in a file"
在es6模块中使用默认导出的任何其他原因?
Any other reason for using default export in es6 modules?
推荐答案
某些差异可能会让您选择其中一个:
Some differences that might make you choose one over the other:
命名导出
- 可以导出多个值
- 导入时必须使用导出的名称
默认导出
- 导出单个值
- 导入时可以使用任何名称
这篇文章很好地解释了何时使用其中一个是个好主意。
This article does a nice job of explaining when it would be a good idea to use one over the other.
这篇关于为什么以及何时在es6模块中使用默认导出而不是命名导出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文