【发布时间】:2021-08-28 18:22:22
【问题描述】:
我正在我的 react native 应用程序的渲染中进行 axios 调用。
render() {
return (
<View style={{flex: 1, backgroundColor: 'white'}}>
<ScrollView
style={styles.scrollView}
contentContainerStyle={{justifyContent: 'center'}}>
<Text style={styles.heading}>Checked Out Books</Text>
{this.state.books.map((book) => {
axios
.get('http://localhost:3000/books/id/' + book)
.then((res) => {
console.log(res.data);
return (
<View>
<Image
source={{uri: res.data.cover}}
height={150}
width={110}></Image>
<Text>{res.data.title}</Text>
</View>
);
})
.catch((err) => {
console.log(err);
alert('Something went wrong.');
});
})}
当调用完成并进入返回步骤时,没有返回任何内容。
我不知道为什么会这样。 这段代码没有返回:
<View>
<Image
source={{uri: res.data.cover}}
height={150}
width={110}></Image>
<Text>{res.data.title}</Text>
</View>
这是为什么?
【问题讨论】:
-
你没有在
map返回任何东西 -
哦,我该怎么做呢?对不起,我是新来的原生反应
标签: javascript react-native axios jsx