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) => {});
},

Logo

加入社区!打开量化的大门,首批课程上线啦!

更多推荐