index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. max-height="250"
  16. style="width: 820px;"
  17. >
  18. <template #action="scope">
  19. <el-button type="text" size="small" @click="deleteRow(scope.$index)">移除</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. export default defineComponent({
  70. // name: 'FluidHeight',
  71. components: {
  72. ComTable
  73. },
  74. setup() {
  75. const tableData = ref<any[]>([
  76. {
  77. date: '2016-05-02',
  78. name: '王小虎',
  79. province: '上海',
  80. city: '普陀区',
  81. address: '上海市普陀区金沙江路 1518 弄',
  82. zip: 200333
  83. },
  84. {
  85. date: '2016-05-04',
  86. name: '王小虎',
  87. province: '上海',
  88. city: '普陀区',
  89. address: '上海市普陀区金沙江路 1517 弄',
  90. zip: 200333
  91. },
  92. {
  93. date: '2016-05-01',
  94. name: '王小虎',
  95. province: '上海',
  96. city: '普陀区',
  97. address: '上海市普陀区金沙江路 1519 弄',
  98. zip: 200333
  99. },
  100. {
  101. date: '2016-05-03',
  102. name: '王小虎',
  103. province: '上海',
  104. city: '普陀区',
  105. address: '上海市普陀区金沙江路 1516 弄',
  106. zip: 200333
  107. },
  108. {
  109. date: '2016-05-02',
  110. name: '王小虎',
  111. province: '上海',
  112. city: '普陀区',
  113. address: '上海市普陀区金沙江路 1518 弄',
  114. zip: 200333
  115. },
  116. {
  117. date: '2016-05-04',
  118. name: '王小虎',
  119. province: '上海',
  120. city: '普陀区',
  121. address: '上海市普陀区金沙江路 1517 弄',
  122. zip: 200333
  123. },
  124. {
  125. date: '2016-05-01',
  126. name: '王小虎',
  127. province: '上海',
  128. city: '普陀区',
  129. address: '上海市普陀区金沙江路 1519 弄',
  130. zip: 200333
  131. },
  132. {
  133. date: '2016-05-03',
  134. name: '王小虎',
  135. province: '上海',
  136. city: '普陀区',
  137. address: '上海市普陀区金沙江路 1516 弄',
  138. zip: 200333
  139. }
  140. ])
  141. const loading = ref<boolean>(true)
  142. setTimeout(() => {
  143. loading.value = false
  144. }, 1000)
  145. function deleteRow(index: number) {
  146. tableData.value.splice(index, 1)
  147. }
  148. return {
  149. columns,
  150. tableData,
  151. loading,
  152. deleteRow
  153. }
  154. }
  155. })
  156. </script>
  157. <style>
  158. </style>