multipleChoice.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <script setup lang="ts">
  2. import { ref } from "vue";
  3. import { tableData } from "./data";
  4. const tableRef = ref();
  5. const multipleSelection = ref([]);
  6. const toggleSelection = (rows?: any) => {
  7. const { toggleRowSelection, clearSelection } = tableRef.value.getTableRef();
  8. if (rows) {
  9. rows.forEach(row => {
  10. toggleRowSelection(row, undefined);
  11. });
  12. } else {
  13. clearSelection();
  14. }
  15. };
  16. const handleSelectionChange = val => {
  17. multipleSelection.value = val;
  18. };
  19. const columns: TableColumnList = [
  20. {
  21. type: "selection",
  22. align: "left"
  23. },
  24. {
  25. label: "日期",
  26. prop: "date"
  27. },
  28. {
  29. label: "姓名",
  30. prop: "name"
  31. },
  32. {
  33. label: "地址",
  34. prop: "address"
  35. }
  36. ];
  37. </script>
  38. <template>
  39. <div>
  40. <pure-table
  41. ref="tableRef"
  42. :data="tableData"
  43. :columns="columns"
  44. @selection-change="handleSelectionChange"
  45. />
  46. <div style="margin-top: 20px">
  47. <el-button @click="toggleSelection([tableData[1], tableData[2]])">
  48. Toggle selection status of second and third rows
  49. </el-button>
  50. <el-button @click="toggleSelection()">Clear selection</el-button>
  51. </div>
  52. </div>
  53. </template>