我有一个expo react原生应用程序,我想在另一个项目中使用我制作的API中的函数。我在Postman中测试了该url,该url运行良好。但我得到了一个错误:应用程序中的Network error failed。
klt_id和klt_name来自客户端表。该url指向一个函数,该函数显示客户端表中的所有记录。
这就是我现在所拥有的:
constructor(props){
super(props);
this.state ={ isLoading: true}
}
componentDidMount(){
return fetch('http://127.0.0.1:8000/api/v2/klant', )
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson)
this.setState({
isLoading: false,
dataSource: responseJson.data,
}, function(){
});
})
.catch((error) =>{
console.error(error);
});
}
render(){
if(this.state.isLoading){
return(
<View style={{flex: 1, padding: 20}}>
<ActivityIndicator/>
</View>
)
}
return(
<View style={{flex: 1, paddingTop:20}}>
<FlatList
data={this.state.dataSource}
renderItem={({item}) => <Text>{item.klt_id}, {item.klt_name}</Text>}
keyExtractor={({id}, index) => id}
/>
</View>
);
}
}提前感谢!
发布于 2020-01-23 21:37:18
https://stackoverflow.com/questions/59855281
复制相似问题