virtual.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <script lang="ts" setup>
  2. import type { VxeGridProps } from '#/adapter/vxe-table';
  3. import { onMounted } from 'vue';
  4. import { Page } from '@vben/common-ui';
  5. import { useVbenVxeGrid } from '#/adapter/vxe-table';
  6. interface RowType {
  7. id: number;
  8. name: string;
  9. role: string;
  10. sex: string;
  11. }
  12. const gridOptions: VxeGridProps<RowType> = {
  13. columns: [
  14. { type: 'seq', width: 70 },
  15. { field: 'name', title: 'Name' },
  16. { field: 'role', title: 'Role' },
  17. { field: 'sex', title: 'Sex' },
  18. ],
  19. data: [],
  20. height: 'auto',
  21. pagerConfig: {
  22. enabled: false,
  23. },
  24. scrollY: {
  25. enabled: true,
  26. gt: 0,
  27. },
  28. showOverflow: true,
  29. };
  30. const [Grid, gridApi] = useVbenVxeGrid({ gridOptions });
  31. // 模拟行数据
  32. const loadList = (size = 200) => {
  33. try {
  34. const dataList: RowType[] = [];
  35. for (let i = 0; i < size; i++) {
  36. dataList.push({
  37. id: 10_000 + i,
  38. name: `Test${i}`,
  39. role: 'Developer',
  40. sex: '男',
  41. });
  42. }
  43. gridApi.setGridOptions({ data: dataList });
  44. } catch (error) {
  45. console.error('Failed to load data:', error);
  46. // Implement user-friendly error handling
  47. }
  48. };
  49. onMounted(() => {
  50. loadList(1000);
  51. });
  52. </script>
  53. <template>
  54. <Page auto-content-height>
  55. <Grid />
  56. </Page>
  57. </template>