和风天气常用api

本文介绍了如何在Vue.js应用中使用QWeatherAPI获取特定城市的天气信息,包括7天预报、当前气象预警和实时空气质量数据,通过发送GET请求并解析响应来实现功能。
摘要由CSDN通过智能技术生成

1.根据城市名获取和风天气id等信息

getWeather() {
      this.$axios({
        method: "GET",
        url: "https://geoapi.qweather.com/v2/city/lookup",
        params: { adm: "河北省", location: "唐山市", key: this.weatherKey },
      }).then((res) => {
        if (res.status == 200) {
          let { location } = res.data;
          this.weather7(location);
          this.weatherWarning(location);
          this.weatherQuality(location);
        }
      });
    },

2.七天预报 参数对应信息

weather7(location) {
      this.$axios({
        method: "GET",
        url: "https://api.qweather.com/v7/weather/7d",
        params: { location: location[0].id, key: this.weatherKey },
      }).then((res) => {
        if (res.status == 200) {
          this.weather= res.data.daily;
        }
      });
},

3.气象预警 参数对应信息

weatherWarning(location) {
      this.$axios({
        method: "GET",
        url: "https://api.qweather.com/v7/warning/now",
        params: { location: location[0].id, key: this.weatherKey },
      }).then((res) => {
        if (res.status == 200) {
          this.warningInfo = res.data;
        }
      });
    },

4.实时空气质量 参数对应信息

weatherQuality(location) {
      this.$axios({
        method: "GET",
        url: "https://api.qweather.com/v7/air/now",
        params: { location: location[0].id, key: this.weatherKey },
      }).then((res) => {});
},

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值