reactjs - fetch 包无法从 API 中获取任何数据
问题描述
我正在开发一个 react js 项目,需要从API
.
我正在使用fetch()
来获取数据。这是我的代码。
fetch('https://sandboxapi.ampcome.com/api/gokhana/restaurant/categorized', {
method: 'GET',
headers: {
'Authorization': 'WqQg2jqLWVIO5JBmQ1LYHU8w41FdzLEsCB6yP1Tw2AFHf2w5KWRkMBV8KAgY6Kl5'
},
qs: {
geopoint: {
near: {
lat: 12.9699,
lng: 77.6499
},
maxDistance: 50,
unit: 'kilometers'
},
categories: ['trending', 'newaddition', 'popular'],
outlettypes: ['restaurant', 'foodcourt'],
clientapp: 'gokhanacustomer'
}
})
.then(res => res.json())
.then(res => console.log(res));
一切都很好,但这会返回空数组。有很多数据,但它返回一个空数组。
我尝试了同样的axios
方法,它获取数据,我无法找出确切的问题fetch()
我需要比较axios
和获取的工作,这就是为什么我需要通过两种方式测试它。
解决方案
推荐阅读
- linux - 在 Linux 中使用 little endian 编译 PowerPC(e5500 系列)
- google-maps - 如何在 Google 地图上显示自定义矢量图块
- php - 从 API 获取多个请求时流明 + Angular 错误 500
- spring-security - Spring Boot 安全配置 OAuthSSO 和 ResourceServer
- ms-access - 将 MS Access 2003 Unicode 字符串读入 VB6
- elasticsearch - 弹性搜索 | 如何搜索嵌套对象?
- javascript - 来自 JSON 文件的 innerHTML
- python - Pandas 中的条形图颜色处理
- angular - Angular 路由器似乎工作但不加载组件
- reactjs - React:如何在应用程序中的功能中重定向?