繁体   English   中英

类型错误:_This.props 未定义

[英]TypeError: _This.props is undefined

我是 React Native 的新手,请帮助我解决这个问题:TypeError: _props.goToScreen is not a function,请帮我提前谢谢

Profile.js 我想点击 GotoHome 按钮并转到另一个页面



export default class Profile extends Component {
 _GotoHome = () => {
   this.props.goToScreen('UploadProduct');
 };

 render() {
   return (

         <ListItem icon>
           <Left>
             <Text>List All Uploaded Product</Text>
           </Left>
           <Body />
           <Right>
             <Icon
               active
               name="angle-right"
               type="FontAwesome"
               onPress={() => this._GotoHome()}
             />
           </Right>
         </ListItem>



   );
 }
}

这是我在个人资料页面 Navigation\\index.js 中的导航

import {createDrawerNavigator, createAppContainer} from 'react-navigation';

import {createStackNavigator} from 'react-navigation-stack';
import {createBottomTabNavigator} from 'react-navigation-tabs';

import UploadProductScreen from './UploadProductScreen';

const ProfileStackNavigator = createStackNavigator(
  {
    Profile: {
      screen: ProfileScreen,
    },
    UploadProduct: {
      screen: UploadProductScreen,
    },
  },
  {headerMode: 'none'},
);





export default createAppContainer(ProfileStackNavigator );

这里是我的 uploadProductScreen 页面

import {UploadProduct} from '@container';

class UploadProductScreen extends Component {
  render() {
    const {navigate} = this.props.navigation;
    return (
      <UploadProduct
        navigation={this.props.navigation}
        goToScreen={(screen, EventId) => navigate(screen, {ItemId: EventId})}
      />
    );
  }
}
export default UploadProductScreen;

在 Profie 组件中定义构造函数以使用 props。

constructor(props) {
    super(props);
 }

我也使用这样的东西来导航到另一个屏幕。

this.props.navigation.navigate("UploadProduct");   // here UploadProduct is the key yo have defined in stack navigator

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM