美文网首页
Element Plus Table 单选

Element Plus Table 单选

作者: 寻找无名的特质 | 来源:发表于2023-12-09 06:59 被阅读0次

将Element Plus Table的多选变为单选,需要做以下的工作。首先,增加select 和selection-change的处理,
@select="handSelectClick" @selection-change="handleSelectionChange"
事件响应的代码如下:

handleSelectionChange(val: any) {
            this.selectedTableData = val;
        },
        handSelectClick(selection: any) {
            if (this.multiplestate) return
            if (selection.length > 1) {
                const del_row = selection.shift();
                (this.$refs["multipleTable"] as any).toggleRowSelection(del_row, false);
            }
        }

需要定义组件内部变量selectedTableData 保存选择的行,然后在选择时判断需要移除的行,因为最多只会同时有两行被选中,所以,只需要移除上一次选中行就可以。然后,还需要隐藏表头的多选框。

相关文章

网友评论

      本文标题:Element Plus Table 单选

      本文链接:https://www.haomeiwen.com/subject/rghvwdtx.html