undefined不是对象(评估this.props.navigation)

问题描述 投票:0回答:1

我试图在导航栏的右上角保持可触摸的不透明度,对于可触摸不透明度的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
    }
}

它正在抛出红色屏幕,上面有错误。请让我知道我哪里出错了。

javascript reactjs react-native ecmascript-6
1个回答
0
投票

试试这是工作:)

         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
                }
            })
© www.soinside.com 2019 - 2024. All rights reserved.