简单demo
①页面:
<template> <el-table ref="multipleTable" :data="tableData3" tooltip-effect="light" style=" 100%" @selection-change="handleSelectionChange" stripe border fit highlight-current-row> <el-table-column type="selection" width="55" :disable="isdisable"> </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> <div style="margin-top: 20px"> <el-button @click="toggleSelection(tableData3)">全选</el-button> <el-button @click="toggleSelection()" :disabled="multipleSelection.length == 0">取消选择</el-button> </div> </template>
②交互:
export default { data() { return { tableData3: [{ date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-08', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-06', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-07', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }], multipleSelection: [], isdisable:false, } }, methods: { //全选,取消选择 toggleSelection(rows) { if (rows) { rows.forEach(row => { this.$refs.multipleTable.toggleRowSelection(row); }); } else { this.$refs.multipleTable.clearSelection(); } }, handleSelectionChange(val) { //val 为选中数据的集合 this.multipleSelection = val; } } }
③效果:
作者:smile.轉角
QQ:493177502