天气预报小程序的设计与实现 |
您所在的位置:网站首页 › 天气微信小程序首页设计 › 天气预报小程序的设计与实现 |
getWeather(city) { var that = this //获取实况天气 wx.request({ url: 'https://api.binstd.com/weather/query?appkey=839c6cf080e63a65&city=' + city, success: (res) => { if (res.data.msg == '城市不存在') { wx.showToast({ title: '抱歉!没有该城市的天气预报', icon: 'none', duration: 2000 }) return; } console.log(res) that.setData({ city: city, temperature: res.data.result.temp, wid: res.data.result.img, direct: res.data.result.winddirect, power: res.data.result.windpower, humidity: res.data.result.humidity, aqi: res.data.result.aqi.aqi, windspeed:res.data.result.windspeed, temphigh:res.data.result.temphigh, templow:res.data.result.templow, pressure:res.data.result.pressure, affect:res.data.result.aqi.aqiinfo.affect, measure:res.data.result.aqi.aqiinfo.measure }) // console.log(that.data.affect); // console.log(that.data.measure); // 24小时天气预报 var arr = res.data.result.hourly var hourly = [] for (var i = 0; i "imgsrc": arr[i].img, "tmp": arr[i].temp, "time": arr[i].time, } } that.setData({ hourly: hourly }) // 未来七天的天气预报 var weekArray = new Array("周日", "周一", "周二", "周三", "周四", "周五", "周六"); var afterSeven = res.data.result.daily var daily_forecast = [] for (var i = 0; i d_txt: i == 0 ? "今天" : weekArray[new Date(arr[i].date).getDay()], d_date: afterSeven[i].date.substring(5), imgsrc_d: afterSeven[i].day.img, imgsrc_n: afterSeven[i].night.img, wind_dir: afterSeven[i].day.winddirect, wind_sc: afterSeven[i].day.windpower, tmp_max: afterSeven[i].day.temphigh, tmp_min: afterSeven[i].night.templow, } } that.setData({ daily_forecast: daily_forecast }) }, fail: (res) => { console.log(res); }, complete: (res) => { console.log(res);}, }) }, |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |