Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 错误:";undefined不是对象(评估';this,props.navigation.navigate';)”;以自然反应_React Native - Fatal编程技术网

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

在React Native中将一页导航到另一页时出错

错误:

undefined不是对象(评估“this,props.navigation.navigate”)

代码:

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值更改为:

    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.”,也不留下“()=>”。这背后的原因是,你不需要调用提交函数,只需传递它。请建议任何链接