thirdScriptError

发布于 6 年前作者 liqin10463 次浏览最后编辑 6 年前来自 ask

我获取和风天气原先是V5可以获取到,现在升级为S6,修改后就报错        

VM2445:1 thirdScriptError

Cannot read property ‘tmp’ of undefined

getWeather: function (city) {

var that = this

var url = https://free-api.heweather.com/s6/weather

var params = {

city: city,

key: “894fc2a749104d679fa022c3e71afe83”

}

wx.request({

url: url,

data: params,

success: function (res) {

var tmp = res.data.HeWeather6[0].now.tmp;

var txt = res.data.HeWeather6[0].now.cond.txt;

var code = res.data.HeWeather6[0].now.cond.code;

var qlty = res.data.HeWeather6[0].aqi.city.qlty;

var dir = res.data.HeWeather6[0].now.wind.dir;

var sc = res.data.HeWeather6[0].now.wind.sc;

var hum = res.data.HeWeather6[0].now.hum;

var fl = res.data.HeWeather6[0].now.fl;

var daily_forecast = res.data.HeWeather6[0].daily_forecast;

that.setData({

tmp: tmp,

txt: txt,

code: code,

qlty: qlty,

dir: dir,

sc: sc,

hum: hum,

fl: fl,

daily_forecast: daily_forecast

})

},

fail: function (res) { },

complete: function (res) { },

})

}

3 回复
msong
msong1 楼6 年前

这根本就是js的基础问题,百度搜索javascript的this问题,看完回来感谢我!

zhanggang
zhanggang2 楼6 年前

res.data.HeWeather6[0].now 是个 undefined

guochao
guochao3 楼4 年前

大家帮忙解答下,感谢