zhongshujie
昨天 ce7cf2f67ec29aef55a889574942c58c8d7737bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<template>
  <keep-alive v-if="keepAliveList.length > 0" :include="keepAliveList">
    <router-view />
  </keep-alive>
  <router-view v-else />
</template>
<script>
import { mapState } from "vuex";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapState(["keepAliveList"]),
  },
  watch: {
    $route(to, from) {
      if (to.meta.keepAlive && this.keepAliveList.indexOf(to.name) == -1) {
        this.$store.commit("addKeepAlive", to.name);
      }
    },
  },
};
</script>