uniapp根据定位城市获取对应的天气 您所在的位置:网站首页 百度地图显示天气预报 uniapp根据定位城市获取对应的天气

uniapp根据定位城市获取对应的天气

2024-06-27 04:59| 来源: 网络整理| 查看: 265

效果如图所示请添加图片描述 首先先获取定位城市

uni.getLocation({ type: 'gcj02', geocode: true, success: res => { this.position = false; this.dizhi = res.address.city; } });

仿照官网上写的,也可以写省份、国家之类的。 用v-if替换文字,显示城市

定位 {{dizhi}}

根据定位城市显示对应的天气

uni.request({ url: 'http://wthrcdn.etouch.cn/weather_mini?city=dizhi', method: 'GET', data:{ city:this.dizhi }, success: res => { var obj:any=res.data; this.high=obj.data.forecast[0].high; this.low=obj.data.forecast[0].low console.log(this.high); console.log(this.low); }, });

这里的语法是用ts写的,ts比js有更多的语法限制。所以在这里加了var obj=res.data



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有