提示:
vue.runtime.esm.js?2b0e:619 [Vue warn]: <transition-group> children must be keyed: <BookshelfItem>
我的代码:
<template>
<div class="bookshelf-list">
<transition-group tag="div" class="bl-list">
<bookshelf-item
v-for="(book, index) in shelfBooks"
:book="book"
:index="index"
:key="book.id"></bookshelf-item>
<item-of-add :key="Math.random()" />
</transition-group>
</div>
</template>
可以看到,我的key已经绑定值了,而且也是唯一的值(一本书只有一个ID),我的另一个组件这么写没问题。
如果说有不同的话就是我那另一个组件没有嵌套其他组件,类似的,我的嵌套的组件都绑定上key,结果还是一样,报这个问题
求解,万分感谢
问题原因:
因为我是根据v-for遍历数据进行展示的,key绑定的数据是使用book的id(book.id),然而如果遍历到一个分类,就没有唯一的id了,所以就会返回undefined, 因此绑定的不是唯一key,即报错