vue3.4中KeepAlive的一个bug

KeepAlive可以缓存组件,在不使用include时没有任何问题,可以正常缓存。
但是一旦使用了include,如果动态组件中没有导入ref函数,缓存功能就消失了
比如
editcom.vue

<template>
  <input >
</template>
<script setup>
import { ref } from 'vue'
</script>
<style>
    
</style>

这个组件导入了ref,则能正常被缓存
app.vue

<div>
	<div>
		<label><input type="radio" v-model="currentcom" :value="editcom"/>editcom</label>
		<label><input type="radio" v-model="currentcom" :value="radiocom"/>radiocom</label>
	</div>
	<KeepAlive include="editcom">
		<component :is="currentcom"></component>
	</KeepAlive>
</div>

切换后输入框中字符串还在
image

如果去掉ref引用,切换后输入框中的字符串就会清空
image
官网案例中刚好两个组件都引用了ref,故而看不到这个现象

posted @   ggtc  阅读(34)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
//右下角目录
点击右上角即可分享
微信分享提示