Ant Design of Vue 表格行动态改变disabled

一次项目开发中遇到需要动态改变ant vue表格行的disabled,查看api有一个getCheckboxProps初始化的时候的disabled实现。后来经过不懈努力终于在官方issues中发现实现方法其实还是借助getCheckboxProps如图所示

1595218700(1).jpg

戳一戳在线代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<template>
<div>
<a-table :columns="columns" :dataSource="data" :rowSelection="rowSelection">
<a
slot="operation"
slot-scope="text,record,index"
@click="handleDisabled(index)"
>activate/disabled</a>
</a-table>
<a-button @click="handleDisabled(3)">activate/disabled</a-button>
</div>
</template>
<script>
export default {
data() {
return {
columns: [
{
title: "Operation",
scopedSlots: { customRender: "operation" }
},
{
title: "Name",
dataIndex: "name"
},
{
title: "Age",
dataIndex: "age"
},
{
title: "Address",
dataIndex: "address"
}
],
data: [
{
key: "1",
name: "John Brown",
age: 32,
address: "New York No. 1 Lake Park",
disabled: false
},
{
key: "2",
name: "Jim Green",
age: 42,
address: "London No. 1 Lake Park",
disabled: false
},
{
key: "3",
name: "Joe Black",
age: 32,
address: "Sidney No. 1 Lake Park",
disabled: false
},
{
key: "4",
name: "Disabled User",
age: 99,
address: "Sidney No. 1 Lake Park",
disabled: true
}
],
selectedRowKeys: ["4"]
};
},
computed: {
rowSelection() {
return {
getCheckboxProps: record => ({
props: {
disabled: record.disabled
}
})
};
}
},
methods: {
handleDisabled(index) {
this.data[index].disabled = !this.data[index].disabled;
// 这一步重新赋值才能实现动态改变disabled
this.data = [...this.data];
}
}
};
</script>

点个赞再走呗