uni 获取天气预报

uni.request({
	url: 'http://wthrcdn.etouch.cn/weather_mini?city=' + city,
	method: 'GET',
	success: res => {
		let today = res.data.data.forecast[0]
		this.todayInfo.weather= today.type ? today.type : ''
		this.todayInfo.lower = today.low.substr(2)
		this.todayInfo.higher = today.high.substr(2)
		this.todayInfo.fengli = today.fengxiang + ' ' + today.fengli.substring(today.fengli.indexOf('A[')+2, today.fengli.indexOf(']]'))
		this.todayInfo.tips = res.data.data.ganmao
		this.date.week = today.date.substr(today.date.indexOf('日') + 1)
		
		let yes = res.data.data.yesterday
		this.yestedayInfo.weather= yes.type ? yes.type : ''
		this.yestedayInfo.lower = yes.low.substr(2)
		this.yestedayInfo.higher = yes.high.substr(2)
		
		let tomorrow = res.data.data.forecast[1]
		this.tomorrowInfo.weather= tomorrow.type ? tomorrow.type : ''
		this.tomorrowInfo.lower = tomorrow.low.substr(2)
		this.tomorrowInfo.higher = tomorrow.high.substr(2)
		
		let afterTomorrow = res.data.data.forecast[2]
		this.afterTomorrowInfo.weather= afterTomorrow.type ? afterTomorrow.type : ''
		this.afterTomorrowInfo.lower = afterTomorrow.low.substr(2)
		this.afterTomorrowInfo.higher = afterTomorrow.high.substr(2)
	},
	fail: () => {
		this.openmsg("警告","天气接口获取失败")
	},
	complete: () => {}
})

tips:
this.todayInfo.weather 今日天气
this.todayInfo.lower 今日最低温度
this.todayInfo.higher 今日最高温度
this.todayInfo.fengli 今日风力
this.todayInfo.tips 今日提醒
this.date.week 今日星期几

this.yestedayInfo 昨日天气情况
this.tomorrowInfo 明日天气情况
this.afterTomorrowInfo 后天天气情况

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值