Skip to content
Source
Sign inSign up
TanStack/virtual
Open History to see the last commit

RowVirtualizerFixed.vue

45 lines1.1 KB

1<template>
2 <div
3 ref="parentRef"
4 class="List"
5 style="height: 200px; width: 400px; overflow: auto"
6 >
7 <div
8 :style="{ height: `${totalSize}px`, width: '100%', position: 'relative' }"
9 >
10 <div
11 v-for="virtualRow in virtualRows"
12 :key="virtualRow.index"
13 :class="virtualRow.index % 2 ? 'ListItemOdd' : 'ListItemEven'"
14 :style="{
15 position: 'absolute',
16 top: 0,
17 left: 0,
18 width: '100%',
19 height: `${virtualRow.size}px`,
20 transform: `translateY(${virtualRow.start}px)`,
21 }"
22 >
23 Row {{ virtualRow.index }}
24 </div>
25 </div>
26 </div>
27</template>
28​
29<script setup lang="ts">
30import { ref, computed } from 'vue'
31import { useVirtualizer } from '@tanstack/vue-virtual'
32​
33const parentRef = ref<HTMLElement | null>(null)
34​
35const rowVirtualizer = useVirtualizer({
36 count: 10000,
37 getScrollElement: () => parentRef.value,
38 estimateSize: () => 35,
39 overscan: 5,
40})
41​
42const virtualRows = computed(() => rowVirtualizer.value.getVirtualItems())
43​
44const totalSize = computed(() => rowVirtualizer.value.getTotalSize())
45</script>