antd报错:Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key

前言:

        使用antd的table时报错这个,查了很多资料,得到结论这个是react的规范,因为数据里面没有key这个表示唯一值,所以报错,记录下问题

解决方法:

 一:(不太实用)让返回值里面添加key这个字段

          {
            key:1,//id改成key
            title: '设备名称',
            dataIndex: 'name',
            width:'auto',
          },
          {
            key:2,
            title: 'ip',
            dataIndex: 'infos.ip',
            width:'auto',
          },.......

二:因为我们使用table返回值必有id,而且是唯一值,设置  rouKey='id'

<a-table
        rowKey="id" //添加这句
        :rowSelection="rowSelection" :dataSource="list" :columns="columns" :pagination='pagination' @change='tableChange'>
        <template slot="operation" slot-scope="scope,record">
            <a @click="editData(record)" href="javascript:;">修改</a><span> | </span>
            <a @click="seeData(record)" href="javascript:;">查看</a><span> | </span>
            <a @click="deleteData(record)" href="javascript:;">删除</a>
        </template>
      </a-table>
发布了128 篇原创文章 · 获赞 49 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/qq_41619796/article/details/103121039