inleft
2022-02-15 91dc6cdda0548ff7f6e473a81933fa206d912cef
commit | author | age
9bcb19 1 <script>
I 2 export default {
3   name: 'RouteView',
4   props: {
5     keepAlive: {
6       type: Boolean,
7       default: true
8     }
9   },
10   data () {
11     return {}
12   },
13   render () {
14     const { $route: { meta }, $store: { getters } } = this
15     const inKeep = (
16       <keep-alive>
17         <router-view />
18       </keep-alive>
19     )
20     const notKeep = (
21       <router-view />
22     )
23     // 这里增加了 multiTab 的判断,当开启了 multiTab 时
24     // 应当全部组件皆缓存,否则会导致切换页面后页面还原成原始状态
25     // 若确实不需要,可改为 return meta.keepAlive ? inKeep : notKeep
26     if (!getters.multiTab && !meta.keepAlive) {
27       return notKeep
28     }
29     return this.keepAlive || getters.multiTab || meta.keepAlive ? inKeep : notKeep
30   }
31 }
32 </script>