el-table表格实现多选功能(全选/指定选中/取消选中)
vue项目开发中,如何实现el-table
表格全选、指定选中、取消选中等功能,下面编程教程网小编给大家详细介绍一下具体实现代码!
template代码
<template>
<el-table
ref="multipleTable"
:data="tableData"
tooltip-effect="dark"
style="width: 100%"
@selection-change="handleSelectionChange">
<el-table-column
type="selection"
width="55">
</el-table-column>
<el-table-column
prop="name"
label="姓名"
width="120">
</el-table-column>
<el-table-column
prop="age"
label="年龄"
show-overflow-tooltip>
</el-table-column>
</el-table>
<div style="margin-top: 20px">
<el-button @click="toggleSelection([tableData[3]])">切换第四行的选中状态</el-button>
<el-button @click="toggleSelection()">取消选择</el-button>
</div>
</template>
script代码
<script>
export default {
data() {
return {
tableData: [],
multipleSelection: []
}
},
methods: {
//如果定义了指定选中项,点击选中指定项,否则取消选中
toggleSelection(rows) {
if (rows) {
rows.forEach(row => {
this.$refs.multipleTable.toggleRowSelection(row);
});
} else {
this.$refs.multipleTable.clearSelection();
}
},
handleSelectionChange(val) {
this.multipleSelection = val;
}
}
}
</script>
以上是编程学习网小编为您介绍的“el-table表格实现多选功能(全选/指定选中/取消选中)”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。