index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div>
  3. <el-alert
  4. effect="dark"
  5. :closable="false"
  6. title="基于 Element 的 Table 组件进行二次封装,实现数据驱动,支持所有 Table 参数 -- 固定列"
  7. type="info"
  8. style="margin-bottom: 20px;"
  9. />
  10. <com-table
  11. v-loading="loading"
  12. :columns="columns"
  13. :data="tableData"
  14. border
  15. style="width: 820px;"
  16. >
  17. <template #action="scope">
  18. <el-button type="text" size="small" @click="handleClick(scope.row)">查看</el-button>
  19. <el-button type="text" size="small">编辑</el-button>
  20. </template>
  21. </com-table>
  22. </div>
  23. </template>
  24. <script lang="ts">
  25. import { defineComponent, ref } from 'vue'
  26. import ComTable from '_c/Table/index.vue'
  27. const columns = [
  28. {
  29. key: 'date',
  30. label: '日期',
  31. fixed: true,
  32. width: '150'
  33. },
  34. {
  35. key: 'name',
  36. label: '姓名',
  37. width: '120'
  38. },
  39. {
  40. key: 'province',
  41. label: '省份',
  42. width: '120'
  43. },
  44. {
  45. key: 'city',
  46. label: '市区',
  47. width: '120'
  48. },
  49. {
  50. key: 'address',
  51. label: '地址',
  52. width: '300'
  53. },
  54. {
  55. key: 'zip',
  56. label: '邮编',
  57. width: '120'
  58. },
  59. {
  60. key: 'action',
  61. label: '操作',
  62. width: '100',
  63. fixed: 'right',
  64. slots: {
  65. default: 'action'
  66. }
  67. }
  68. ]
  69. const tableData = [
  70. {
  71. date: '2016-05-02',
  72. name: '王小虎',
  73. province: '上海',
  74. city: '普陀区',
  75. address: '上海市普陀区金沙江路 1518 弄',
  76. zip: 200333
  77. },
  78. {
  79. date: '2016-05-04',
  80. name: '王小虎',
  81. province: '上海',
  82. city: '普陀区',
  83. address: '上海市普陀区金沙江路 1517 弄',
  84. zip: 200333
  85. },
  86. {
  87. date: '2016-05-01',
  88. name: '王小虎',
  89. province: '上海',
  90. city: '普陀区',
  91. address: '上海市普陀区金沙江路 1519 弄',
  92. zip: 200333
  93. },
  94. {
  95. date: '2016-05-03',
  96. name: '王小虎',
  97. province: '上海',
  98. city: '普陀区',
  99. address: '上海市普陀区金沙江路 1516 弄',
  100. zip: 200333
  101. }
  102. ]
  103. export default defineComponent({
  104. // name: 'FixedColumn',
  105. components: {
  106. ComTable
  107. },
  108. setup() {
  109. const loading = ref<boolean>(true)
  110. setTimeout(() => {
  111. loading.value = false
  112. }, 1000)
  113. function handleClick(row: any) {
  114. console.log(row)
  115. }
  116. return {
  117. columns,
  118. tableData,
  119. loading,
  120. handleClick
  121. }
  122. }
  123. })
  124. </script>
  125. <style>
  126. </style>