thirdScriptError
发布于 5 年前 作者 liqin 10281 次浏览 来自 问答

我获取和风天气原先是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 回复

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

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

大家帮忙解答下,感谢

回到顶部