import React from 'react';
import { FlatList, ActivityIndicator, Text, View } from 'react-native';
export default class FetchExample extends React.Component {
constructor(props){
super(props);
this.state ={ isLoading: true}
}
componentDidMount(){
fetch('https://apitest.kuveytturk.com.tr/prep/v1/data/fecs', {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
firstParam: 'isoCode ',
secondParam: 'internationalCode',
thirdParam: 'name',
fourthParam: 'code',
FifthParam: 'group',
SixthParam: 'id'
}),
});
}
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.isoCode}, {item.internationalCode}, {item.name}, {item.code}, {item.group}</Text>}
keyExtractor={({id}, index) => id}
/>
</View>
);
}
}
我是 React Native 的初学者,我正在尝试从 api 获取数据,但我有一个关于代码的错误。
possible unhandled promise rejection (id 0) typeerror undefined is not an object
我不明白为什么没有对象
希望得到您的帮助。
最佳答案
请注意,您不能在 GET 请求中使用正文。请更改为 POST。
关于javascript - 可能未处理的 promise 拒绝(id 0)类型错误 GET 或 HEAD 请求不允许主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58498360/