<el-table :data="tableData" tooltip-effect="dark" style="width: 100%" ref="multipleTable" @select-all="onSelectAll" @selection-change="selectItem" @row-click="onSelectOp"> <el-table-column type="selection" width="55"> </el-table-column> <el-table-column label="日期" width="120"> <template slot-scope="scope">{{ scope.row.date }}</template> </el-table-column> <el-table-column prop="name" label="姓名" width="120"> </el-table-column> <el-table-column prop="address" label="地址" show-overflow-tooltip> </el-table-column> </el-table>
@select-all="onSelectAll" 全选事件:在点击全选的时候,把所有的选中状态清空,执行 clearSelection() ;
@selection-change="selectItem" 选中某一个 checkbox 事件做判断,选中数量大于一就把上一个选中的数据勾选状态改为 false ,把新的数据勾选状态设为 true ,并赋值给 multipleSelection 数组,方便调用;
@row-click="onSelectOp" 单击某行事件单击某行,就把某行的选中状态设为 true ,在此之前执行 clearSelection()
methods: { onSelectAll() { this.$refs.multipleTable.clearSelection(); }, selectItem(rows) { if (rows.length > 1) { var newRows = rows.filter((it, index) => { if (index == rows.length - 1) { this.$refs.multipleTable.toggleRowSelection(it, true); return true; } else { this.$refs.multipleTable.toggleRowSelection(it, false); return false; } }); this.multipleSelection = newRows; } else { this.multipleSelection = rows; } }, onSelectOp(row) { this.$refs.multipleTable.clearSelection(); this.$refs.multipleTable.toggleRowSelection(row, true); this.multipleSelection = []; this.multipleSelection.push(row); }, }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
2020-09-03 vue 项目后端传过来的图片地址拼接域名显示
2020-09-03 vue 项目移动端 PC端自适应
2020-09-03 微信小程序,控制文字显示的行数
2020-09-03 vue 实现 获取验证码倒计时