Vue3使用keep-alive实现组件缓存

2021-04-08 10:07:57 浏览数 (1)

代码语言:javascript复制
<template>
  <router-view v-slot="{ Component }">
    <keep-alive :include="includeList">
      <component :is="Component" />
    </keep-alive>
  </router-view>
</template>

<script lang="ts">
import { ref, defineComponent } from "vue";
export default defineComponent({
  name: "App",
  setup() {
    // 需要缓存的组件name值
    const includeList = ref(["index"]);
    return {
      includeList,
    };
  },
});
</script>

0 人点赞