【问题标题】:undefined is not an object (Evaluating this.props.navigation)undefined 不是对象(评估 this.props.navigation)
【发布时间】:2017-12-18 06:36:36
【问题描述】:

我试图在导航栏的右上角保持可触摸的不透明度,用于可触摸不透明度的 onPress。我想把用户带到主页。

constructor(props) {
    super(props);
    this.state = {
        stAccntList: [],
        stUserAccountNo: '',
        stCustNo: '',
        resp: '',
    };


}
static navigationOptions = {
    //  title: 'myacc',
    title: 'My Accounts',
    headerRight: <TouchableHighlight onPress={() => {
        this.props.navigation.navigate('home');
    }}>
        <Image style={{ marginRight: 20 }} source={require('../../../resources/toolbar/home_inactive.png')} />
    </TouchableHighlight>,
    headerTintColor: 'white',
    headerStyle: {
        backgroundColor: colors.themeColor,
        //  top: 30
    }
}

上面的错误会引发红屏。请让我知道我哪里出错了。

【问题讨论】:

  • 您希望thisthis.props.navigation.navigate('home'); 中引用什么?

标签: javascript reactjs react-native ecmascript-6


【解决方案1】:

试试这个它是工作:)

         static navigationOptions = ({navigation}) => ({
                title: 'My Accounts',
                headerRight: <TouchableHighlight onPress={() => {
                    navigation.navigate('home');
                }}>
                <Image style={{ marginRight: 20, height: 30, width: 30 }}
source={{ uri:https://media.freepik.com/accounts/img/badges/downloads_gold.png' 
    }} />
                </TouchableHighlight>,
                headerTintColor: 'white',
                headerStyle: {
                    backgroundColor: colors.themeColor,
                    //  top: 30
                }
            })

【讨论】:

  • 哥们。添加代码后出现语法错误.. 编辑器中有一些红色标记。
  • 我正在更新 navigationOptions 。这是工作 %100 @KartiikeyaBaleneni
  • “试试这个就行了” 为什么? OP的代码有什么问题?你改变了什么?
  • @FelixKling 我创建了新的 RN 项目。我有两个屏幕。帐户和主页。然后我在两个屏幕上都添加了 navigationOptions = ({navigation}) => {....}。它抛出了一个错误。我改变了 navigationOptions = ({navigation}) => ({.....});然后它的工作。如果它不起作用,找我;)
  • 是什么让您认为应该为navigationOptions 分配一个函数
猜你喜欢
  • 1970-01-01
  • 2018-11-12
  • 1970-01-01
  • 2015-07-16
  • 2020-07-16
  • 2018-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多