auto-resizer.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <template>
  2. <div style="height: 400px">
  3. <el-auto-resizer>
  4. <template #default="{ height, width }">
  5. <el-table-v2
  6. :columns="columns"
  7. :data="data"
  8. :width="width"
  9. :height="height"
  10. fixed
  11. />
  12. </template>
  13. </el-auto-resizer>
  14. </div>
  15. </template>
  16. <script lang="ts" setup>
  17. const generateColumns = (length = 10, prefix = 'column-', props?: any) =>
  18. Array.from({ length }).map((_, columnIndex) => ({
  19. ...props,
  20. key: `${prefix}${columnIndex}`,
  21. dataKey: `${prefix}${columnIndex}`,
  22. title: `Column ${columnIndex}`,
  23. width: 150,
  24. }))
  25. const generateData = (
  26. columns: ReturnType<typeof generateColumns>,
  27. length = 200,
  28. prefix = 'row-'
  29. ) =>
  30. Array.from({ length }).map((_, rowIndex) => {
  31. return columns.reduce(
  32. (rowData, column, columnIndex) => {
  33. rowData[column.dataKey] = `Row ${rowIndex} - Col ${columnIndex}`
  34. return rowData
  35. },
  36. {
  37. id: `${prefix}${rowIndex}`,
  38. parentId: null,
  39. }
  40. )
  41. })
  42. const columns = generateColumns(10)
  43. const data = generateData(columns, 200)
  44. </script>