【问题标题】:Import ES Module in react native unidentified将 ES Module 导入到 react native unidentified
【发布时间】:2018-06-12 16:29:14
【问题描述】:

我想将屏幕导入我的反应导航,但是当我导入类 React.Component 时,它的身份不明

我的路由.js

import * as Screens from '../screens/index';
import {FontIcons} from '../assets/icons';

export const MainRoutes = [
  {
    id: 'LoginMenu',
    title: 'Marketing',
    icon: FontIcons.login,
    screen: Screens.GridV1,
    children: [
      {
        id: 'Login1',
        title: 'Login V1',
        screen: Screens.GridV1,
        children: []
      },
      {
        id: 'Login2',
        title: 'Login V2',
        screen: 'GridV2',
        children: []
      },
      {
        id: 'SignUp',
        title: 'Sign Up',
        screen: 'GridV2',
        children: []
      },
      {
        id: 'password',
        title: 'Password Recovery',
        screen: 'GridV2',
        children: []
      },
    ]
  }
];

我的屏幕/index.js

export * from './navigation';
export * from './dash';

当我检查屏幕导入时

console.log(Screens);

一切都很好。但是当我执行时

console.log(Screens.GridV1);

我无法访问 GridV1 类

请帮我解决这里的问题。谢谢你

【问题讨论】:

  • 你能显示'../screens/index'的代码吗?
  • @Val 我已经给出了我的“../screens/index”。我认为我的屏幕目录没有问题

标签: javascript android react-native ecmascript-6 react-navigation


【解决方案1】:

从您的Screens 的 chrome 快照中可以看出,此时您的console.logScreens 对象仅包含一个元素{__esModule: true}GridV1GridV2 和所有其他模块都延迟解决了。

因此您应该看到它可以与 setTimeout 一起使用,例如:

setTimeout( () => console.log(Screens.GridV1), 100 );

但真正的问题仍然隐藏在背后。通常import javascript 模块不会有这样的副作用,它应该可以按您的预期工作。检查这些模块是否有任何特殊的初始化机制。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    • 2020-07-09
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多