gpt4 book ai didi

javascript - 未定义不是对象 (UIConstants)

转载 作者:行者123 更新时间:2023-11-30 14:28:18 26 4
gpt4 key购买 nike

在 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')

最佳答案

你不能在声明中引用同一个类。尝试早点定义高度:

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;
}

关于javascript - 未定义不是对象 (UIConstants),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51591847/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com