React native 错误:";undefined不是对象(评估';this,props.navigation.navigate';)”;以自然反应
在React Native中将一页导航到另一页时出错 错误: undefined不是对象(评估“this,props.navigation.navigate”) 代码:React native 错误:";undefined不是对象(评估';this,props.navigation.navigate';)”;以自然反应,react-native,React Native,在React Native中将一页导航到另一页时出错 错误: undefined不是对象(评估“this,props.navigation.navigate”) 代码: import { StackNavigator,NavigationActions } from "react-navigation"; const Navigation = StackNavigator({ Home : { screen : Home }, }) export default class
import { StackNavigator,NavigationActions } from "react-navigation";
const Navigation = StackNavigator({
Home : {
screen : Home
},
})
export default class App extends React.Component {
submit = () => {
this.props.navigation.navigate('Home');
}
render() {
return (
<View style={styles.container}>
<Text>Enter Log</Text>
<TextInput style={styles.input}
multiline={true}
underlineColorAndroid="transparent"
placeholder="Enter Log"
placeholderTextColor="#9a73ef"
autoCapitalize="none"
onChangeText={this.handlePassword} />
<TouchableOpacity style={styles.submitButton} onPress={() => submit } >
<Text style={styles.submitButtonText}> Submit </Text>
</TouchableOpacity>
</View>
);
}
}
}
从“react navigation”导入{StackNavigator,NavigationActions};
const Navigation=StackNavigator({
主页:{
屏幕:主页
},
})
导出默认类App扩展React.Component{
提交=()=>{
this.props.navigation.navigate('Home');
}
render(){
返回(
输入日志
提交}>
提交
);
}
}
}
onPress={this.submit}
您必须绑定您的方法:
import { StackNavigator,NavigationActions } from "react-navigation";
const Navigation = StackNavigator({
Home : {
screen : Home
},
})
export default class App extends React.Component {
constructor(props) {
super(props);
this.submit = this.submit.bind(this);
}
render() {
return (
<View style={styles.container}>
<Text>Enter Log</Text>
<TextInput style={styles.input}
multiline={true}
underlineColorAndroid="transparent"
placeholder="Enter Log"
placeholderTextColor="#9a73ef"
autoCapitalize="none"
onChangeText={this.handlePassword} />
<TouchableOpacity style={styles.submitButton} onPress={this.submit} >
<Text style={styles.submitButtonText}> Submit </Text>
</TouchableOpacity>
</View>
);
}
submit() {
this.props.navigation.navigate('Home');
}
}
从“react navigation”导入{StackNavigator,NavigationActions};
const Navigation=StackNavigator({
主页:{
屏幕:主页
},
})
导出默认类App扩展React.Component{
建造师(道具){
超级(道具);
this.submit=this.submit.bind(this);
}
render(){
返回(
输入日志
提交
);
}
提交(){
this.props.navigation.navigate('Home');
}
}
说明:更改后出现错误:找不到变量:提交使用过的链接:除了我的建议之外,您是否做了任何其他更改?试着只留下“{submit}”,而不留下“this.”,也不留下“()=>”。这背后的原因是,你不需要调用提交函数,只需传递它。请建议任何链接