Skip to main content
Vuetify0 is now in alpha!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

createVirtual

Virtual scrolling composable for efficiently rendering large lists by only rendering visible items.

Usage

The createVirtual composable efficiently renders large lists by only mounting visible items plus a small overscan buffer. Pass an array of items and configure the item height to get back sliced items, scroll handlers, and positioning values.

vue
<script setup lang="ts">
  import { createVirtual } from '@vuetify/v0'
  import { shallowRef } from 'vue'

  const items = shallowRef(
    Array.from({ length: 10_000 }, (_, i) => `Item ${i + 1}`)
  )

  const { element, items: visible, offset, size, scroll, scrollTo } = createVirtual(items, {
    itemHeight: 40,
  })
</script>

<template>
  <div ref="element" class="h-[300px] overflow-y-auto" @scroll="scroll">
    <div :style="{ height: `${offset}px` }" />
    <div v-for="item in visible" :key="item.index">
      {{ item.raw }}
    </div>
    <div :style="{ height: `${size}px` }" />
  </div>
</template>

Context / DI

Use createVirtualContext to share a virtual scroll instance across a component tree:

ts
import { createVirtualContext } from '@vuetify/v0'
import { shallowRef } from 'vue'

const items = shallowRef([...])

export const [useVirtual, provideVirtual, virtual] =
  createVirtualContext(items, {
    namespace: 'my:virtual',
    itemHeight: 40,
  })

// In parent component
provideVirtual()

// In child component
const { items: visible, offset, size, scroll } = useVirtual()

Architecture

The rendering pipeline transforms scroll events into visible item ranges:

Reactivity

Property/MethodReactiveNotes
elementRef, assign scroll container
itemsComputed, visible items with index
offsetShallowRef, readonly (top spacer height)
sizeShallowRef, readonly (bottom spacer height)
stateShallowRef ('loading' | 'empty' | 'error' | 'ok')
scroll()Call on @scroll; schedules a visible-range update via rAF
scrollend()Call on @scrollend; alias of scroll()
scrollTo(index, options?)Scroll to item by index; accepts behavior, block, offset
resize(index, height)Notify of a dynamic item height change; triggers offset rebuild
reset()Reset state to 'ok' and restore scroll anchor
Tip

Source items The items ref passed to createVirtual() is watched for changes. When items change, the virtual scroller updates automatically.

Examples

API Reference

The following API details are for the createVirtual composable.

Benchmarks

Every operation is profiled across multiple dataset sizes to measure real-world throughput. Each benchmark is assigned a performance tier—good, fast, blazing, or slow—and groups are scored by averaging their individual results so you can spot bottlenecks at a glance. This transparency helps you make informed decisions about which patterns scale for your use case. Learn more in the benchmarks guide.

View benchmark source↗

Was this page helpful?

Ctrl+/