jsonp请求没返回数据
来源:3-8 头部组件实现(2)

allencth
2018-07-10
我用的openWeahterMap, 返回不到数据,但是用postman又返回,这个什么问题
getWeatherAPIData(){
let city = 'Brisbane'
let appid = '1d8b0e3ad58a9f70188f4abaa1c8336a'
axios.jsonp({
url: 'api.openweathermap.org/data/2.5/weather?q={city}&appid={appid}'
}).then((res) => {
if (res.cod == 200) {
let data = res.weather[0]
this.setState({
city: res.name,
weather: data.description
})
}
}).catch((err) => {
console.log(err)
})
}
---
static jsonp(options){
return new Promise((resolve, reject) => {
JsonP(options.url, {
param: 'callback',
timeout: 80000
}, function(err,data){
console.log(data)
if (data.cod == '200') {
resolve(data)
} else{
reject(data.message)
}
})
})
}
---
postman返回的数据
{
"coord": {
"lon": 153.03,
"lat": -27.47
},
"weather": [
{
"id": 801,
"main": "Clouds",
"description": "few clouds",
"icon": "02d"
}
],
"base": "stations",
"main": {
"temp": 293.68,
"pressure": 1023,
"humidity": 49,
"temp_min": 293.15,
"temp_max": 294.15
},
"visibility": 10000,
"wind": {
"speed": 3.6,
"deg": 180
},
"clouds": {
"all": 20
},
"dt": 1531188000,
"sys": {
"type": 1,
"id": 8164,
"message": 0.0078,
"country": "AU",
"sunrise": 1531168692,
"sunset": 1531206502
},
"id": 2174003,
"name": "Brisbane",
"cod": 200
}
1回答
-
河畔一角
2018-07-10
调试,检查返回数据格式,根据错误提示进行排查。这个地址放在浏览器是可以正常请求的,说明是没有问题的。
10
相似问题