記錄用ant.design 3x中遇到的一個奇葩錯誤。在使用ant 3.x table 進行開發時,已經設置了rowkey="id",但仍然報Each child in a list should have a unique "key" prop. 錯誤。嘗試許久,後發現是columns 配置問題,配置如下,columns 第一個元素必須設置dataIndex,否則即使設置了rowkey也會報錯。其他元素是否設置dataIndex沒有問題。不過第一個元素如果同時設置render,那麼設置dataIndex會使render失效。
const columns = [
{
title: '客戶類型',
render: record => {
return oUserType[record.userType]
},
},
{
title: '客戶名稱',
dataIndex: 'userName',
},
]