auto-resizer.vue 1.2 KB

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