代码之家  ›  专栏  ›  技术社区  ›  Roger Coll

未定义不是对象(uiconstants)

  •  1
  • Roger Coll  · 技术社区  · 6 年前

    在React Native中,我有这个类(来自Kittentricks):

      import {Platform} from 'react-native';
    
    export class UIConstants {
      static AppbarHeight = Platform.OS === 'ios' ? 44 : 56;
      static StatusbarHeight = Platform.OS === 'ios' ? 20 : 0;
      static HeaderHeight = UIConstants.AppbarHeight + UIConstants.StatusbarHeight;
    }
    

    类的名称:appconstants.js

    问题是当我尝试导出这个类时。我得到这个错误:

    undefined is not an object(evaluating 'UIConstants.AppbarHeight')
    
    2 回复  |  直到 6 年前
        1
  •  2
  •   hsz    6 年前

    const appbarHeight = Platform.OS === 'ios' ? 44 : 56;
    const statusbarHeight = Platform.OS === 'ios' ? 20 : 0;
    
    export class UIConstants {
      static AppbarHeight = appbarHeight;
      static StatusbarHeight = statusbarHeight;
      static HeaderHeight = appbarHeight + statusbarHeight;
    }
    
        2
  •  0
  •   Wakeel    6 年前

    import {UIConstants} from './UIConstants'

    import UIConstants from './UIConstants'