maioyan icon indicating copy to clipboard operation
maioyan copied to clipboard

keep-alive小性能优化~

Open yaogengzhu opened this issue 5 years ago • 0 comments

对于keep-alive需要使用activated来代替mounted来重新加载数据

data() {
    return {
      allCity: [], // 存放城市数据
      isLoading: true,
      cityId: -1 // 优化ID
    };
  },
  activated() {
    // console.log('ok')
    let cityId = this.$store.state.city.id;
    if (this.cityId === cityId) return;
    this.isLoading = true;
    this.axios.get("/api/cinemaList?cityId=" + cityId).then(res => {
      // console.log(res)
      // 判断数据是否请求成功
      if (res.status === 200) {
        // 将数据赋值到存放的数据数组中
        this.allCity = res.data.data.cinemas;
        this.cityId = cityId;
        this.isLoading = false;
      }
    });
  },

yaogengzhu avatar May 19 '19 05:05 yaogengzhu