赞
踩
// 关键是 :row-key="rowKey" :reserve-selection="true"
<el-table :data="tableData" @selection-change="handleSelectionChange" height="480" style="width: 100%;height: 100%;border: 2px solid rgba(0, 125, 252, 0.27);padding-bottom: 10px" :row-key="rowKey" ref="fileTable">
<el-table-column type="selection" width="55" :reserve-selection="true" :selectable="selectAble"></el-table-column>
</el-table>
// rowKey方法
rowKey(row) {
return row.id
},
// 关键是 @selection-change="handleSelectionChange" :selectable="selectAble" <el-table :data="tableData" @selection-change="handleSelectionChange" height="480" style="width: 100%;height: 100%;border: 2px solid rgba(0, 125, 252, 0.27);padding-bottom: 10px" :row-key="rowKey" ref="fileTable"> <el-table-column type="selection" width="55" :reserve-selection="true" :selectable="selectAble"></el-table-column> </el-table> // rowKey方法 selectAble(row) { if (row.status === 1) { return true; } return false; }, handleSelectionChange(val) { this.multipleSelection = val; //选中的数据 if (this.multipleSelection.length >= this.checkNum) { //checkNum 默认最多选中几条 this.$message.warning(`最多只能选${this.checkNum}条数据`); for (let j of this.tableData) { //向选中的数据中添加字段,根据添加字段使用selectAble()方法 j.status = 0; for (let i of this.multipleSelection) { if (i.id == j.id) { j.status = 1; } } } return } else { for (let i in this.tableData) { this.tableData[i].status = 1; } } },
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。