T
TanStack3y ago
equal-aqua

Vue (Beta): Is there an example of for usage? (+ Questions)

I understand the vue adapater is in beta. I'm trying to test it and hopefully improve.
<script lang="ts" setup>
import { ref } from "vue";
import { useVirtualizer } from "@tanstack/vue-virtual";

const items = ref(new Array(10000)
.fill(true)
.map(() => 25 + Math.round(Math.random() * 100)));

const scrollElement = ref();

const virtualizerOptions = ref({
getScrollElement: () => scrollElement.value,
estimateSize: (i) => items[i],
count: items.length
});
</script>

<template>
<!-- The scrollable element -->
<div ref="scrollElement" :style="{
height: '100%',
width: '100%',
overflowY: 'auto',
contain: 'strict'
}">
<!-- The large inner element to hold all of the items -->
<div :style="{
height: virtualizer.getTotalSize(),
width: '100%',
position: 'relative'
}">
<!-- Only the visible items in the virtualizer, manually positioned to be in view -->
<div v-for="item in items" :key="item.key" :style="{
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: `${item.size}px`,
transform: `translateY(${item.start}px)`
}">
{{ item.index }}
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { useVirtualizer } from "@tanstack/vue-virtual";

const items = ref(new Array(10000)
.fill(true)
.map(() => 25 + Math.round(Math.random() * 100)));

const scrollElement = ref();

const virtualizerOptions = ref({
getScrollElement: () => scrollElement.value,
estimateSize: (i) => items[i],
count: items.length
});
</script>

<template>
<!-- The scrollable element -->
<div ref="scrollElement" :style="{
height: '100%',
width: '100%',
overflowY: 'auto',
contain: 'strict'
}">
<!-- The large inner element to hold all of the items -->
<div :style="{
height: virtualizer.getTotalSize(),
width: '100%',
position: 'relative'
}">
<!-- Only the visible items in the virtualizer, manually positioned to be in view -->
<div v-for="item in items" :key="item.key" :style="{
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: `${item.size}px`,
transform: `translateY(${item.start}px)`
}">
{{ item.index }}
</div>
</div>
</div>
</template>
Issues: 1. If I don't provide overscan then I can't scroll. (Picture 1 is without overscan, and picture 2 is with overscan of 64) 2. I have more nodes but the scroll ends without loading more items. Questions: - How do I dynamically increase item count? - How do I achieve dynamic sizing via vue? Side note: I'm more than happy to try and help bring the vue implementation to life.
No description
No description
3 Replies
metropolitan-bronze
metropolitan-bronze3y ago
Same, please help
national-gold
national-gold3y ago
Would also appreciate to see different vue examples in the docs
metropolitan-bronze
metropolitan-bronze3y ago
Bump Bump @Maintainer - Virtual Bump Bump

Did you find this page helpful?