1
liuying
2024-04-25 6e3b6044ba218ba2c7cf4ad9d80821d8f78f1ff0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<script>
export default {
  name: 'RouteView',
  props: {
    keepAlive: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {}
  },
  render () {
    const { $route: { meta }, $store: { getters } } = this
    const inKeep = (
      <div style="height:100%;box-sizing:border-box;padding:24px 24px 0 24px;overflow:auto;">
        <div class="content" style="margin:0;height:100%;">
          <div class="page-header-index-wide" style="height:100%;">
            <keep-alive>
              <router-view />
            </keep-alive>
          </div>
        </div>
      </div>
    )
    
    /* const inKeep = (
      <keep-alive>
        <router-view />
      </keep-alive>
    ) */
    
    const notKeep = (
      <div style="height:100%;box-sizing:border-box;padding:24px 24px 0 24px;overflow:auto;">
        <div class="content" style="margin:0;height:100%;">
          <div class="page-header-index-wide" style="height:100%;">
            <router-view />
          </div>
        </div>
      </div>
    )
    /* const notKeep = (
      <router-view />
    ) */
    // 这里增加了 multiTab 的判断,当开启了 multiTab 时
    // 应当全部组件皆缓存,否则会导致切换页面后页面还原成原始状态
    // 若确实不需要,可改为 return meta.keepAlive ? inKeep : notKeep
    if (!getters.multiTab && !meta.keepAlive) {
      return notKeep
    }
    return this.keepAlive || getters.multiTab || meta.keepAlive ? inKeep : notKeep
  }
}
</script>