<template>
  <el-button @click="toggleSelectionAll">全选</el-button>
  <el-button @click="toggleSelectionInverse">反选</el-button>
  <el-button @click="clearSelection">清空</el-button>
  <el-table
    ref="multipleTable"
    :data="tableData"
    @selection-change="handleSelectionChange"
    style="width: 100%">
    <el-table-column
      type="selection"
      width="55">
    </el-table-column>
    <!-- 其他列定义 -->
  </el-table>
</template>
 
<script>
export default {
  data() {
    return {
      tableData: [
        // 数据列表
      ],
      multipleSelection: []
    };
  },
  methods: {
    toggleSelectionAll() {
      this.$refs.multipleTable.toggleAllSelection();
    },
    toggleSelectionInverse() {
      this.$refs.multipleTable.toggleRowSelection(
        this.tableData.filter(row => this.multipleSelection.indexOf(row) === -1),
        true
      );
    },
    clearSelection() {
      this.$refs.multipleTable.clearSelection();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    }
  }
};
</script>这个例子中,我们定义了三个按钮用于执行全选、反选和清空已选择项的操作。handleSelectionChange 方法用于更新选中项的数组。toggleSelectionAll 方法使用表格的 toggleAllSelection 方法来切换所有行的选中状态。toggleSelectionInverse 方法通过调用 toggleRowSelection 方法来反选当前未选中的行。clearSelection 方法清空当前的选择。这些方法都通过 $refs 访问表格实例来执行相应的操作。