主页点击哪个城市,显示哪个城市的数据

import { mapState } from "vuex";

导入mapState

  computed: {
    ...mapState(["cityName"]),
  },

循环请求到的数据,判断是否点击的文字和请求到的数据是否一样

  methods: {
    http() {
      let that = this;
      this.axios.get("http://localhost:8080/api/dataHome.json").then((res) => {
        //   console.log(res.data.data);
        let data = res.data.data;
        data.forEach((item) => {
          if (that.cityName == item.city) {
            console.log(item);
            that.spikeList = item.spikeList;
            that.likeList = item.likeList;
          }
        });
      });
    },
  },

 

posted @ 2020-04-17 18:50  金翅扑街鸟  阅读(125)  评论(0)    收藏  举报