demo9.vue 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <m-table
  3. ref="singleTableRef"
  4. :data="tableData"
  5. highlight-current-row
  6. @on-current-change="handleCurrentChange">
  7. <m-table-column type="index" width="55" />
  8. <m-table-column prop="date" label="日期" />
  9. <m-table-column prop="name" label="姓名" />
  10. <m-table-column prop="address" label="地址" />
  11. </m-table>
  12. <div style="margin-top: 20px">
  13. <m-button @click="handleClearCurrentRow">取消选择</m-button>
  14. </div>
  15. </template>
  16. <script setup>
  17. import { ref } from 'vue-demi';
  18. const singleTableRef = ref(null)
  19. const tableData = [
  20. {
  21. date: '2022-05-12',
  22. name: '后裔',
  23. address: '王者峡谷下塔旁'
  24. },
  25. {
  26. date: '2022-06-13',
  27. name: '鲁班',
  28. address: '在逛街'
  29. },
  30. {
  31. date: '2022-07-14',
  32. name: '孙尚香',
  33. address: '在打红buff'
  34. },
  35. {
  36. date: '2022-08-15',
  37. name: '狄仁杰',
  38. address: '在推塔'
  39. }
  40. ]
  41. const handleCurrentChange = (val) => {
  42. console.log(val);
  43. }
  44. const handleClearCurrentRow = () => {
  45. singleTableRef.value.clearCurrentRow()
  46. }
  47. </script>