2017-06-13 72 views
0

的反应,就是这两者之间的区别:`import {history}`和`import history`有什么区别?

import {history} from '../../app/setup.js'; 

import history from '../../app/setup.js'; 

感谢

+0

可能重复[在reactjs中,何时应在导入时添加括号](https://stackoverflow.com/questions/41337709/in-reactjs-when-should-i-add-brackets-when-import) –

回答

2

这取决于封装的导出格式。如果setup.js设置一个default出口,像

// setup.js 
export default history 

然后import history from …将它捡起来。此语法将在当前模块中将整个导出从setup.js分配到history

如果出口是这样的:

// setup.js 
export { history } 

然后import {history} from …将它捡起来。此语法在从setup.js导出的模块中查找.history属性。

相关问题