gpt4 book ai didi

javascript - TypeError : _This. Prop 未定义

转载 作者:行者123 更新时间:2023-11-28 03:10:44 26 4
gpt4 key购买 nike

我是 React Native 的新手,请帮助我解决这个问题:TypeError: _props.goToScreen 不是一个函数,请帮助我提前致谢

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

关于javascript - TypeError : _This. Prop 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60145087/

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