Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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
Reactjs 如何在react native中发送参数_Reactjs_Api_React Native_Parameters_Navigation - Fatal编程技术网

Reactjs 如何在react native中发送参数

Reactjs 如何在react native中发送参数,reactjs,api,react-native,parameters,navigation,Reactjs,Api,React Native,Parameters,Navigation,在这里我进行了登录,成功登录后我将id参数发送到主页, 在主页上,我根据登录用户id显示数据。我在登录页面上发送了一个参数 之后,我将参数返回主页,但这里的结果为空。 如何正确解析数据 页面登录 //function login fetch (......) .then((response) => response.json()) .then((responseJson) => { if(responseJs

在这里我进行了登录,成功登录后我将id参数发送到主页, 在主页上,我根据登录用户id显示数据。我在登录页面上发送了一个参数

之后,我将参数返回主页,但这里的结果为空。 如何正确解析数据

页面登录

 //function login 
    fetch (......)
      .then((response) => response.json())
            .then((responseJson) => {
              if(responseJson.status == 'ok'){
                this.props.navigation.navigate('home', { id_user: id_user });
              }
              else if(responseJson.status == 'failed') {
              ....
             }


    <Button block info style={styles.mainBtn} onPress={this.login}>
       <Text style={styles.btnText}>Submit</Text>
    </Button>

在主页上,这里我想解析正在记录的id数据,但是当我在
主页
屏幕中控制台时,结果是空的,请尝试在
componentDidMount
生命周期方法中获取
id\u user

componentDidMount(){
const id=this.props.navigation.state.params.id\u用户
控制台日志(id)
//…代码的其余部分
}
如果这不起作用,请在
登录
屏幕中如下配置
导航
语句

if(responseJson.status==“ok”){
this.props.navigation.navigate({'home',{id_user:id_user}});
}

undifine是非objct评估此props.route.paramI的,我现在已经更新了答案,你能试试吗@结果是不精确的
componentDidMount(){
      const { params } = this.props.navigation.state; 
      console.log(params)

      const url = 'https://example.com/data?id_user='+params.id_user
      fetch(url)
      .then((response)=> response.json())
      .then((responseJson)=>{
        // console.log(responseJson.data)
          this.setState({
              dataSource: responseJson.data,
              isLoading : false
          })
      })
      .catch((error)=>{
          console.log(error)
      })
  }