antd getCheckboxProps 点击全选按钮,禁用错乱

需求:列表支持复选,全选,某些数据复选框禁用

按ant design vue官网:




computed: {
    rowSelection() {
      const { selectedRowKeys } = this;
      return {
        onChange: (selectedRowKeys, selectedRows) => {
          console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
        },
        getCheckboxProps: record => ({
          props: {
            disabled: record.name === 'Disabled User', // Column configuration not to be checked
            name: record.name,
          },
        }),
      };
    },
  },

问题:全选时,禁用复选框错乱。

image.png

解决:由于版本antd更新的原因,给数据加上key属性
数据:(注意key),若你的数据没有key属性,需对数据进行处理,增加key属性

const data = [
  {
    key: '1',
    name: 'John Brown',
    age: 32,
    address: 'New York No. 1 Lake Park',
  },
  {
    key: '2',
    name: 'Jim Green',
    age: 42,
    address: 'London No. 1 Lake Park',
  },
  {
    key: '3',
    name: 'Joe Black',
    age: 32,
    address: 'Sidney No. 1 Lake Park',
  },
  {
    key: '4',
    name: 'Disabled User',
    age: 99,
    address: 'Sidney No. 1 Lake Park',
  },
];

你可能感兴趣的:(antd getCheckboxProps 点击全选按钮,禁用错乱)