问题描述
我试图将来自我的 api 的 json 响应保存在一个状态中,然后将它显示在一个平面列表中,但它没有保存状态或显示响应
这是我使用 get 的异步请求
doctors = async() => {
try{
const response = await api.get('/auth/list')
const dataJson = response.json()
console.log(dataJson)
this.setState({places: dataJson.results })
我正在尝试保存在地方状态,但它没有发生,甚至 console.log 也没有显示任何内容
}catch(response){
this.setState({errorMessage: response.data.error})
console.log(err)
}
}
在这里我尝试将它呈现在一个平面列表中,但它没有保存任何东西,所以它什么也没显示
使成为() {
const 位置 = this.state.places
返回(
item.id}
renderItem={({ item }) => {
<View key={item.id} style={styles.place} >
<Text style={styles.title}>{item.title}</Text>
<Text>{item.speciality}</Text>
<Button styes = {styles.button} title = 'View Profile'onPress ={() => navigation.navigate('Profile')} >{item.title}</Button>
</View>
}
}
/>
</SafeAreaView>
)
}
}
这是我的api页面
import {create} from 'apisauce'
const api = create({
baseURL: 'lt url'
})
api.addResponseTransform( response => {
if (!response.ok) throw response
})
export default api;
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)