fluidHeight.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <script setup lang="ts">
  2. import { ref } from "vue";
  3. import dayjs from "dayjs";
  4. import { tableDataMore } from "./data";
  5. const columns: TableColumnList = [
  6. {
  7. label: "日期",
  8. prop: "date",
  9. width: "260",
  10. fixed: true
  11. },
  12. {
  13. label: "姓名",
  14. prop: "name",
  15. width: "260"
  16. },
  17. {
  18. label: "地区",
  19. prop: "state",
  20. width: "260"
  21. },
  22. {
  23. label: "城市",
  24. prop: "city",
  25. width: "260"
  26. },
  27. {
  28. label: "地址",
  29. prop: "address",
  30. width: "260"
  31. },
  32. {
  33. label: "邮编",
  34. prop: "post-code",
  35. width: "260"
  36. },
  37. {
  38. label: "操作",
  39. width: "120",
  40. fixed: "right",
  41. slot: "operation"
  42. }
  43. ];
  44. const now = new Date();
  45. const tableData = ref(tableDataMore);
  46. const deleteRow = (index: number) => {
  47. tableData.value.splice(index, 1);
  48. };
  49. const onAddItem = () => {
  50. now.setDate(now.getDate() + 1);
  51. tableData.value.push({
  52. date: dayjs(now).format("YYYY-MM-DD"),
  53. name: "Tom",
  54. address: "No. 189, Grove St, Los Angeles",
  55. state: "California",
  56. city: "Los Angeles",
  57. "post-code": "CA 90036"
  58. });
  59. };
  60. </script>
  61. <template>
  62. <div>
  63. <pure-table :data="tableData" :columns="columns" maxHeight="500">
  64. <template #operation="{ $index }">
  65. <el-button
  66. link
  67. type="primary"
  68. size="small"
  69. @click.prevent="deleteRow($index)"
  70. >
  71. Remove
  72. </el-button>
  73. </template>
  74. </pure-table>
  75. <el-button class="w-full mt-4!" @click="onAddItem"> Add Item </el-button>
  76. </div>
  77. </template>