index.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. />
  15. </div>
  16. </template>
  17. <script lang="ts">
  18. import { defineComponent, ref } from 'vue'
  19. import ComTable from '_c/Table/index.vue'
  20. const tableData = [
  21. {
  22. date: '2016-05-02',
  23. name: '王小虎',
  24. address: '上海市普陀区金沙江路 1518 弄'
  25. }, {
  26. date: '2016-05-04',
  27. name: '王小虎',
  28. address: '上海市普陀区金沙江路 1517 弄'
  29. }, {
  30. date: '2016-05-01',
  31. name: '王小虎',
  32. address: '上海市普陀区金沙江路 1519 弄'
  33. }, {
  34. date: '2016-05-03',
  35. name: '王小虎',
  36. address: '上海市普陀区金沙江路 1516 弄'
  37. }
  38. ]
  39. export default defineComponent({
  40. // name: 'CustomIndex',
  41. components: {
  42. ComTable
  43. },
  44. setup() {
  45. const loading = ref<boolean>(true)
  46. setTimeout(() => {
  47. loading.value = false
  48. }, 1000)
  49. const columns = ref<any[]>([
  50. {
  51. key: 'index',
  52. type: 'index',
  53. index: (index: number) => {
  54. return index * 2
  55. }
  56. },
  57. {
  58. key: 'date',
  59. label: '日期'
  60. },
  61. {
  62. key: 'name',
  63. label: '姓名'
  64. },
  65. {
  66. key: 'address',
  67. label: '地址'
  68. }
  69. ])
  70. return {
  71. columns,
  72. tableData,
  73. loading
  74. }
  75. }
  76. })
  77. </script>
  78. <style>
  79. </style>