gaoluyang
2026-06-29 27cd042df9aca0383a49f3514bc21958dd890912
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
<!-- 本组件用于获取缓存的route并保存到pinia -->
<script setup lang="ts">
import type { VNode } from 'vue';
import type { RouteLocationNormalizedLoadedGeneric } from 'vue-router';
 
import { watch } from 'vue';
 
import { useTabbarStore } from '../../../../stores/src';
 
interface Props {
  component?: VNode;
  route: RouteLocationNormalizedLoadedGeneric;
}
 
/**
 * 这是页面缓存组件,不做任何的的实际渲染
 */
defineOptions({
  render() {
    return null;
  },
});
const props = defineProps<Props>();
 
const { addCachedRoute } = useTabbarStore();
 
watch(
  () => props.route,
  () => {
    if (props.component && props.route.meta.domCached) {
      addCachedRoute(props.component, props.route);
    }
  },
  { immediate: true },
);
</script>