vue key的bug

今天遇到一个bug,列表删除元素时,明明在外层设置了key,但是列表元素的状态居然复用了,找了好久原因,最后是key的取值问题,记录一下。

首先key可以取undefine,这个是不会报错的

然后项目的代码结构是这样的

js 复制代码
<component
    v-for="(item, index) in showList"
    :is="getComponent(item.type)"
    :key="item[index]"
    :data="item"
 >
 </component>

问题就在于,数据源的item中是有index这个属性的,并且作为id是唯一的,但是取的时候,是通过item[index]取的,index不是变量嘛,so

所有的key都是undefined了,哈哈哈。

相关推荐
hui函数6 小时前
Python系列Bug修复|如何解决 pip install 安装报错 invalid command ‘bdist_wheel’(缺少 wheel)问题
python·bug·pip
hui函数6 小时前
Python系列Bug修复|如何解决 pip install -r requirements.txt 私有索引未设为 trusted-host 导致拒绝 问题
python·bug·pip
hui函数7 小时前
Python系列Bug修复|如何解决 pip install 安装报错 Backend ‘setuptools.build_meta’ 不可用 问题
python·bug·pip
hui函数9 小时前
Python系列Bug修复|如何解决 pip install -r requirements.txt 私有仓库认证失败 401 Unauthorized 问题
python·bug·pip
hui函数9 小时前
Python系列Bug修复|如何解决 pip install -r requirements.txt 子目录可编辑安装缺少 pyproject.toml 问题
python·bug·pip
啊湘1 天前
VSCODE英文界面切换为中文(适用CURSOR等使用)
ide·vscode·编辑器·bug·cursor
hui函数1 天前
Python系列Bug修复|如何解决 pip install -e . 安装报错 “后端不支持可编辑安装(PEP 660)” 问题
python·bug·pip
一条咸鱼_SaltyFish1 天前
[Day16] Bug 排查记录:若依框架二次开发中的经验与教训 contract-security-ruoyi
java·开发语言·经验分享·微服务·架构·bug·开源软件
luming-022 天前
报错解决:IDEA终端输出和CMD终端输出Maven版本不一致
java·缓存·bug·intellij-idea
秃头小饼干2 天前
技术文章大纲:Bug悬案侦破大会
bug