在使用Ant Design for React对接数据时发现控制台报错如下:
Warning: antd: Table Each record in dataSource of table should have a unique key
prop, or set rowKey
of Table to an unique primary key, see https://u.ant.design/table-row-key
其实不是必须的,我们在使用中会发现 "key" 是 mysql 的保留字段,很不方便。可以通过下面的方法解决:
可以给你的数据定一个 dataIndex 之类的值,最后会赋值到 react 的元素 key 上:
rowKey : record => record.dataIndex,
或者
rowKey : (record,index)=> index
我是通过下面的方法解决的:
<Table columns={columns} dataSource={list} rowKey={(record, index) => index} pagination={false} bordered />
这样就不会报错了。
声明:本文由w3h5原创,转载请注明出处:《Ant Design Table组件报错,提示table should have a unique
key
prop的解决办法》 https://cloud.tencent.com/developer/article/1537775