设置Avue-crud的selection复选框某种状态下禁用
时间: 2023-12-07 17:03:51 浏览: 254
可以通过使用 Avue-crud 的 scoped slot 来自定义表格的列,从而实现在某种状态下禁用 selection 复选框。
具体实现方法如下:
1. 在 `crud-config` 中定义需要自定义的列,将该列的 `type` 设置为 `selection`。
2. 在 `crud-config` 中定义需要禁用 selection 复选框的状态。
3. 在模板中使用 `crud` 组件,并在 `crud` 组件中定义 `scopedSlots` 属性。
4. 在 `scopedSlots` 中定义对应的列的渲染方式。
5. 在渲染方式中添加判断,当处于需要禁用的状态时,禁用 selection 复选框。
代码示例:
```html
<template>
<div>
<avue-crud :crud-config="crudConfig" :data="tableData" @selection-change="handleSelectionChange">
<template v-slot:columns="{columns}">
<el-table-column type="selection" :selectable="isSelectable" />
<el-table-column prop="name" label="姓名" />
<el-table-column prop="age" label="年龄" />
</template>
</avue-crud>
</div>
</template>
<script>
export default {
data() {
return {
crudConfig: {
columns: [
{ prop: '', label: '', type: 'selection' },
{ prop: 'name', label: '姓名' },
{ prop: 'age', label: '年龄' }
],
disableSelection: true
},
tableData: [
{ name: '张三', age: 20 },
{ name: '李四', age: 25 },
{ name: '王五', age: 30 }
]
}
},
methods: {
handleSelectionChange(selection) {
console.log(selection)
},
isSelectable(row) {
if (this.crudConfig.disableSelection) {
// 处于需要禁用的状态时,禁用 selection 复选框
return false
} else {
return true
}
}
}
}
</script>
```
在上述代码中,我们通过设置 `crudConfig.disableSelection` 为 `true` 来表示需要禁用 selection 复选框的状态,然后在 `isSelectable` 方法中添加判断,当处于该状态时,禁用 selection 复选框。最终效果如下图所示:

阅读全文
相关推荐


















