使用 Antd 中的 Table 组件 时,报错 Warning: Each child in a list should have a unique “key” prop.
代码如下: const myColumns = [ { title: 'ID', dataIndex: 'id', key: 'id', }, { title: '姓名', dataIndex: 'name', key: 'name', }, ]; const dataSource = [] <Table dataSource={dataSource} columns={myColumns} />; React 需要的 key,如果已经设置了唯一的 dataIndex,可以忽略这个属性。 但,即使加了这个属性,也会报错,继续看看文档,发现了rowKey这个属性 注解:rowKey 表格行 key 的取值,可以是字符串或一个函数 这个值才是真正 tbody 中数据循环中需要设置的key值。 解决方法: <Table columns={columns} dataSource={data} rowKey={record => record.admin_no}/>; 参考: https://blog.csdn.net/weixin_42728767/article/details/119218303 |
|
|