vue 表格 选中后置灰(且有回显,不可重复选择)

1.效果:

 2.代码:首先找到这个标签加上这个方法(注意别加错了标签!!!!)

 <el-table-column type="selection" width="55" align="center" :selectable="selectableDIS"/>

3.主要看return返回什么      (这个效果是全部置灰)

selectableDIS(row){

return false

},

                        3.1 这个效果是选中的置灰不选中的不置灰  可以自己加判断条件

                                        //判断条件自己过滤就行 (原理就是把选中的数据名字装到一个数组里,然后筛选,数组里有就返回false置灰,没有就返回true可以被选择)

                                selectableDIS(row, index) {

                                if (this.Array.indexOf(row.userName) !== -1) {

                                return false

                                } else {

                                return true

                                }

                                }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现表格单选,可以使用 `type="radio"` 属性,然后在选中某一行时,遍历整个表格,将其他行的选中状态都设为 false。 下面是一个示例代码: ```vue <template> <a-table :columns="columns" :dataSource="dataSource"> <template slot="name" slot-scope="{text, record}"> <span v-if="!record.disabled">{{ text }}</span> <span v-else style="color: gray">{{ text }}</span> </template> </a-table> </template> <script> export default { data() { return { columns: [ { title: 'Name', dataIndex: 'name', scopedSlots: { customRender: 'name' }, }, { title: 'Age', dataIndex: 'age', }, { title: 'Address', dataIndex: 'address', }, ], dataSource: [ { 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', disabled: true, // 表示不可选状态 }, ], selectedRowKeys: [], // 当前选中的行 }; }, methods: { handleRowClick(record) { // 点击行时触发 if (record.disabled) { return; // 如果当前行不可选,直接返回 } const { selectedRowKeys } = this; const index = selectedRowKeys.indexOf(record.key); if (index > -1) { selectedRowKeys.splice(index, 1); // 如果当前行已经选中,则取消选中 } else { selectedRowKeys.splice(0, selectedRowKeys.length, record.key); // 否则将当前行设为选中 } this.dataSource.forEach((item) => { if (item.key !== record.key) { item.disabled = true; // 将其他行的状态设为不可选 } else { item.disabled = false; } }); }, }, }; </script> ``` 这里假设接口返回的数据都是一些基本的表格数据,没有特殊的要求。如果需要更复杂的操作,可以根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值