UNIAPP获取天气

onLoad() {

uni.request({
						url: 'http://wthrcdn.etouch.cn/weather_mini?city=沈阳',
						method: 'GET',
						success: res => {
							console.log("今天的天气",res.data.data.forecast[0].type);
							console.log("今天最高温度",res.data.data.forecast[0].high);
							console.log("今天最低温度",res.data.data.forecast[0].low);
							console.log("目前气温",res.data.data.wendu);
							
							console.log("明天的天气",res.data.data.forecast[1].type);
							console.log("明天最高温度",res.data.data.forecast[1].high);
							console.log("明天最低温度",res.data.data.forecast[1].low);
						},
						fail: () => {
							this.openmsg("警告","天气接口获取失败")
						},
						complete: () => {}
			});

}

接收到请求内容:

{
	"data": {
		"data": {
			"city": "沈阳",
			"forecast": {
				"0": {
					"date": "8日星期二",
					"fengli": "<![CDATA[2级]]>",
					"fengxiang": "南风",
					"high": "高温 30℃",
					"low": "低温 19℃",
					"type": "晴"
				},
				"1": {
					"date": "9日星期三",
					"fengli": "<![CDATA[3级]]>",
					"fengxiang": "南风",
					"high": "高温 29℃",
					"low": "低温 19℃",
					"type": "多云"
				},
				"2": {
					"date": "10日星期四",
					"fengli": "<![CDATA[2级]]>",
					"fengxiang": "南风",
					"high": "高温 23℃",
					"low": "低温 18℃",
					"type": "雷阵雨"
				},
				"3": {
					"date": "11日星期五",
					"fengli": "<![CDATA[2级]]>",
					"fengxiang": "东风",
					"high": "高温 27℃",
					"low": "低温 17℃",
					"type": "多云"
				},
				"4": {
					"date": "12日星期六",
					"fengli": "<![CDATA[2级]]>",
					"fengxiang": "东风",
					"high": "高温 30℃",
					"low": "低温 18℃",
					"type": "多云"
				},
				"length": 5
			},
			"ganmao": "感冒易发期,外出请适当调整衣物,注意补充水分。",
			"wendu": "29",
			"yesterday": {
				"date": "7日星期一",
				"fl": "<![CDATA[2级]]>",
				"fx": "南风",
				"high": "高温 29℃",
				"low": "低温 14℃",
				"type": "多云"
			}
		},
		"desc": "OK",
		"status": 1000
	},
	"errMsg": "request:ok",
	"header": {
		"access-control-allow-headers": "*",
		"access-control-allow-methods": "*",
		"access-control-allow-origin": "*",
		"age": "115",
		"cache-control": "must-revalidate, max-age=300",
		"connection": "keep-alive",
		"content-encoding": "gzip",
		"content-length": "412",
		"date": "Tue, 08 Jun 2021 07:12:28 GMT",
		"server": "Tengine/2.3.2",
		"x-via-ucdn": "HIT by 218.60.55.7, MISS by 180.97.190.59"
	},
	"statusCode": 200
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值