在使用antd的组件Table时,遇到如下报错:
Each child in a list should have a unique "key" prop.
字面意思就是:
列表中的每个子元素都应该有一个唯一的“key”道具
我使用的方式:
const colunm = [
{
key:'name',
title:'姓名',
dataIndex'name'
},
{
key:'sex',
title:'性别',
dataIndex'sex'
},
{
key:'address',
title:'地址',
dataIndex'address'
}
]
const dataSource = [
{name: 'name1', sex:'男', address:'address1'},
{name: 'name2', sex:'男', address:'address2'}
]
render(){
return <Table columns={columns} dataSource={dataSource} pagination={false} />
}
既然知道错误原因,直接修改 添加rowKey
即可.
代码修改为如下:
...
...
render(){
return <Table columns={columns} dataSource={dataSource} pagination={false} rowKey="id"/>
}
详情可参考: antd table