Vue 3中keepAlive的include属性缓存部分路由不生效?

作者站长头像
站长
· 阅读数 18

vue3中使用keepAlive的include属性不生效

Vue 3中keepAlive的include属性缓存部分路由不生效?Vue 3中keepAlive的include属性缓存部分路由不生效?我想只缓存/template-allocation这个路由,但是没有生效。想通过vue-devtools查找下组件的名称:Vue 3中keepAlive的include属性缓存部分路由不生效?发现组件名字为Index,所以找到问题了

回复
1个回答
avatar
test
2024-06-18

Vue DevTools 中确认一下,你的 components:is 挂载组件名称是否是 TemplateAllocation 这个名称。


answer image你的组件名叫 Index,不是你setup里面的 name:TemplateAllocation。你使用了 setup 之后默认是你的组件文件名 👉 #自动名称推导 - SFC 语法定义 | Vue.js

#defineOptions() - script setup | Vue.js 指定一下组件名称好了。

<script setup>
defineOptions({
  name: 'TemplateAllocation',
})
</script>

社区好像有过一个 script:name 的语法糖,和 script:setup 一样。但是不知道实际落地没有:

<script setup name="TemplateAllocation">
...
</script>
回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容