在做vue多选框的时候,禁止多选,当时想都没想直接在computed里面把row-selection 直接当成方法写在里面了,但是后来发现一些状态不能用,比如清楚多选,selectedRowKeys没有效果,这里记录一下
// 最开始的代码。 但是这种情况只在初识话的时候去执行,后面不会执行,<a-tableref="table"size="middle":scroll="{ x: 1200, y: scrollHeightFun }"borderedrowKey="id":columns="columns":dataSource="dataSource":pagination="ipagination":loading="loading":rowSelection="rowSelection"@change="handleTableChange"...
computed: {rowSelection() {return {onChange: (selectedRowKeys, selectionRows) => {this.selectedRowKeys = selectedRowKeysthis.selectionRows = selectionRows},getCheckboxProps: record => ({props: {disabled: record.oaStatus !== 1 || record.oaStatus === 4 // 待审核 审核驳回的可以勾选}})}}},// 优化后的<a-tableref="table"size="middle":scroll="{ x: 1200, y: scrollHeightFun }"borderedrowKey="id":columns="columns":dataSource="dataSource":pagination="ipagination":loading="loading":row-selection="{selectedRowKeys: selectedRowKeys,onChange: onSelectChange,getCheckboxProps: getCheckboxProps}"@change="handleTableChange">// 下面两种写法都可以 methods: {getCheckboxProps: record => ({props: {disabled: record.oaStatus !== 1 || record.oaStatus === 4 // 待审核 审核驳回的可以勾选}}),getCheckboxProps(record) {return {props: {disabled: record.oaStatus !== 1 || record.oaStatus === 4 // 待审核 审核驳回的可以勾选}}},
}