其他分享
首页 > 其他分享> > Vue3使用keep-alive实现组件缓存

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

作者:互联网

<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>

标签:缓存,name,alive,includeList,Vue3,组件,keep,ref,defineComponent
来源: https://blog.csdn.net/AK852369/article/details/115483769