vue3之el-table单选

el-table文档中没有表格数据单选,因此基于复选框实现数据单选限制。

主要实现代码

bash 复制代码
<el-table :data="tableList" ref="tableRef" @select="selectClick">
	...
</table>

// method
const selectClick = (selection) => {
  let selectRow = {};
  if (selection.length > 1) {
    let del_row = selection.shift(); // 删除选中的第一项
    tableRef.value.toggleRowSelection(del_row, false); //并改变table勾选状态
  }

  // 到这selection数据始终为1条
  if (selection.length) {
    selectRow = selection[0];
  }
  emit("getRow", selectRow);
};
相关推荐
FungLeo2 小时前
成为全栈·Node 后端篇·后端工程从零搭建:TypeScript、目录与热更新
javascript·typescript·node 后端
2601_962203512 小时前
【SpringBoot3】面向切面 AspectJ AOP 使用详解
开发语言·前端·python
XLYcmy3 小时前
HTML/CSS/JS 基础与 Vue 技术栈深度解析
java·前端·css·html·vue3·vue2·api
新知图书3 小时前
12.3 智能体中Skill的约束与自进化实战
java·前端·数据库
风月说与山鬼3 小时前
四、Tailwind CSS——间距与尺寸
前端·css·tailwind css
en.en..3 小时前
C语言 static函数与头文件封装规范
java·c语言·前端
计算机魔术师3 小时前
旅途中用手机远程控制电脑?电脑不在身边,ToDesk/UU远程/TeamViewer移动端深度实测
前端
风月说与山鬼4 小时前
三、Tailwind CSS——排版与文字样式
前端·css·tailwind css
eokred4 小时前
图片预览组件的另一种设计:Headless、可组合、开箱即用
前端·react