vue3 keep-alive include失效问题

在使用vue3 keep-alive时,发现并没有起作用, 代码如下:

<template>
  <div class="app-main">
    <router-view v-slot="{ Component }">
    <keep-alive :include="cachedViews && cachedViews.map((x:any) => x.name)">
      <component :is="Component" />
    </keep-alive>
  </router-view>
  </div>
</template>

<script lang="ts" setup>
import { useLayoutStore } from '../../../stores';
import { storeToRefs } from 'pinia';
const store = useLayoutStore();
const { cachedViews } = storeToRefs(store);
</script>

<style lang="scss" scoped>
.app-main {
  padding: 10px;
  height: calc(100vh - 90px);
  width: 100%;
}
</style>

这里的include绑定的是路由名称的数组,看着没什么问题,就是不起作用。

原来vue3的setup无法组件命名,keep-alive include必须要组件命名

所以在需要添加缓存的组件中,添加:

<script lang="ts">
export default { name: 'charts1' };
</script>

这里的charts1就是该组件名,对应路由的name也是charts1。

参考地址:https://blog.csdn.net/guang_sszbs/article/details/123236594

 

相关推荐

  1. vue3 keep-alive include失效问题

    2024-04-08 10:24:05       37 阅读
  2. 初学vue3与ts:keep-alive的简单使用

    2024-04-08 10:24:05       54 阅读
  3. VUE3,自定义控制keep-alive缓存

    2024-04-08 10:24:05       48 阅读
  4. Vue3中使用缓存组件keep-alive vue3缓存组件

    2024-04-08 10:24:05       64 阅读
  5. vue this.$toast 失效问题汇总

    2024-04-08 10:24:05       40 阅读
  6. Vue-组件缓存-keep-alive

    2024-04-08 10:24:05       51 阅读
  7. vuekeep-alive 详解

    2024-04-08 10:24:05       29 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-08 10:24:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-08 10:24:05       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-08 10:24:05       82 阅读
  4. Python语言-面向对象

    2024-04-08 10:24:05       91 阅读

热门阅读

  1. [Algorithm][双指针][复写零]详细解读 + 代码实现

    2024-04-08 10:24:05       42 阅读
  2. 比赛记录:Codeforces Global Round 25 A~E (猜猜题场)

    2024-04-08 10:24:05       29 阅读
  3. Solr面试题

    2024-04-08 10:24:05       33 阅读
  4. 缓存更新策略

    2024-04-08 10:24:05       33 阅读
  5. P1308 统计单词数

    2024-04-08 10:24:05       36 阅读
  6. 工业视觉AI应用总结记录

    2024-04-08 10:24:05       26 阅读
  7. Android14系统go版添加微件功能

    2024-04-08 10:24:05       28 阅读