如何在JavaScript中导入多个内容

选择

我想在js中导入多个内容,我尝试过import *这样的操作:

导出文件AppEpics.js:

export fooEpic = Observable.of() // some fancy code;
export barEpic = Observable.of() // some other fancy code;

导入文件:

import * as App from './AppEpics'
export default combineEpics(...App)

我发现在登录时App,我得到了一个包含foo和bar的对象,但是在登录时,却...App什么也没有。

我正在使用babel预设环境并立即做出反应。我该如何解决?

顺便说一句,combinedEpics只接受像fooEpics这样的史诗,因此我不能这样调用此函数:

import * as App from './AppEpics'
export default combineEpics(App) // that will not work.
塞尔吉·沃罗贝(Sergii Vorobei)

App是你的情况的对象,并尝试将其作为传播论据功能combineEpics(...App),因为这只会工作,如果应用程序是数组。

如果要将所有导出的值传递到其中combineEpics,则需要执行类似操作combineEpics(...Object.values(App))export default [foo, bar]在App.js和import App from './App' and combineEpics(...App)文件中添加

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章