【发布时间】:2018-07-29 08:10:40
【问题描述】:
有人可以帮助我吗?我不断收到错误消息(见标题)。
我知道以前在 StackOverflow 上很多人都问过这个问题。我阅读了他们的答案,但是当我粘贴解决方案时,我仍然遇到此错误。
下面是代码。
非常感谢。
//Jimmy code
import { Navigation } from 'react-native-navigation';
import { StackNavigator } from 'react-navigation';
import { Merchant2 } from "./../Merchant2/Merchant2";
export class Login extends React.Component{
constructor(prop) {
super(prop);
Navigation.events().bindComponent(this);
this.state = {
userName: "",
password: "",
isVerify: false
};
this.onPress=this.onPress.bind(this);
}
onPress = () => {
//const { navigate } = this.props.navigation;
navigate('Page2');
alert(1)
}
render() {
navigationOptions = {
title: 'Results',
};
return (
<View style={[styles.formFooter]}>
<TouchableHighlight style={[commonStyles.alignItemsCenter, styles.loginBtn]}
activeOpacity={1}
underlayColor={'#cdcdcf'}
onPress={this.onPress.bind(this)}
>
);
};
}
const App = StackNavigator({
Home: { screen: Merchant2 },
});
export default App;
【问题讨论】:
-
为什么评论
//const { navigate } = this.props.navigation; -
嗨,如果我评论这 3 行,我仍然会遇到问题。常量 { 导航 } = this.props.navigation;导航('Page2');警报(1)
-
导航道具被传递到每个屏幕组件......所以这里它只在你的
Merchant2中可用,所以如果你想在Login中使用它,然后像<Login nav={this.props.navigation}/>一样......跨度>
标签: reactjs react-native react-navigation