Each record in dataSource of table should have a unique `key` prop, or set `rowKey` of Table to an unique primary key
原因
表的dataSource中的每个记录都应该具有唯一的“key”属性,或者将表的“rowKey”设置为唯一的主键,报错是因为table每一行的key重复了
解决办法
- columns有id的,直接写。只要在columns中有不重复的字段都可以做key值,如电话号码、身份证等,此时
<a-table
rowKey="phone"
>
<a-table
rowKey="idNumber"
>
- columns找不到不重复的值时,可以使用index,在这里可以使用JSON.stringfy(record)查看这里的record是什么
<a-table
:columns="columns"
:data-source="list"
:rowKey="(record, index) => {return index}"
>
- 如果columns是双层数据结构,并且有id,可以使用如下方式。没有id也可以使用index
大功告成