Reactjs 如何在react native中发送参数
在这里我进行了登录,成功登录后我将id参数发送到主页, 在主页上,我根据登录用户id显示数据。我在登录页面上发送了一个参数 之后,我将参数返回主页,但这里的结果为空。 如何正确解析数据 页面登录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
//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)
})
}