npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@jason12306/vue-async-virtual-scroll

v1.0.3

Published

High-performance asynchronous virtual scroll component for Vue 3 with dynamic height support and optimized rendering for large datasets

Downloads

13

Readme

async-virtual-scroll - Vue3 Asynchronous Virtual Scroll Component

High-performance virtual scroll component supporting dynamic height rendering, optimized for large data list display

简体中文

react version

Features

  • 🚀 Efficient rendering of massive datasets
  • 📏 Supports fixed height and dynamic height
  • 🔍 Automatically calculates visible area content
  • 🔄 Built-in scroll optimization and buffer mechanism
  • ⏳ Smart loading state management
  • 🔧 Highly customizable configuration

Installation & Usage

Install

npm install @jason12306/vue-async-virtual-scroll

Basic Usage

<template>
  <div class="test-container">
    <div class="scroll-container">
      <async-virtual-scroll v-model="show" :data="items" :item-size="60">
        <template v-slot="{ item, dataUid }">
          <div class="list-item" :data-uid="dataUid" :style="{ backgroundColor: item.color }">
            {{ item.id }}. {{ item.text }}
          </div>
        </template>
      </async-virtual-scroll>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { ref, onMounted } from 'vue'
  import AsyncVirtualScroll from '@jason12306/vue-async-virtual-scroll'
  import '@jason12306/vue-async-virtual-scroll/vue-async-virtual-scroll.css'

  const show = ref(false)
  const num = 500
  const items = ref([])

  for (let i = 1; i <= num; i++) {
    items.value.push({
      id: i,
      text: `Item ${i}`,
      color: i % 2 ? '#e0f7fa' : '#fffde7',
    })
  }

  onMounted(() => {
    show.value = true
  })
</script>

<style scoped>
  .test-container {
    padding: 20px;
  }
  .scroll-container {
    height: 500px;
    border: 1px solid #ddd;
    overflow: auto;
  }
  .list-item {
    height: 60px;
    line-height: 60px;
    padding: 0 16px;
    border-bottom: 1px solid #eee;
    box-sizing: border-box;
  }
</style>

Props Configuration

| Name | Type | Required | Default | Description | | ----------- | ------- | --------------------------- | ---------- | ------------------------------------------------------------------------ | | v-model | Boolean | Yes | false | Controls whether virtual scrolling is enabled (must use v-model binding) | | ban | Boolean | No | false | Disable virtual scrolling (for small datasets) | | itemSize | Number | Required for fixed height | undefined | Item height in fixed-height mode (px) | | minItemSize | Number | Required for dynamic height | undefined | Minimum item height in dynamic-height mode (px) | | data | Array | Yes | [] | Data array to render | | buffer | Array | No | [200, 200] | Buffer zone sizes [top buffer, bottom buffer] (px) | | keyField | String | No | 'id' | Field name for unique identifier in data items | | dataUid | String | No | 'data-uid' | DOM attribute name for storing data unique identifier | | viewNum | Number | No | 1 | Minimum number of items visible initially (for estimation) |

Slots

default

Main rendering slot for defining each item's content

Slot Parameters

| Parameter | Type | Description | | --------- | ------ | ---------------------- | | item | Object | Current data item | | index | Number | Item index in data | | dataUid | String | Item unique identifier |

Usage Scenarios

1. Fixed Height Mode

When all items have the same height, use fixed height mode for optimal performance:

<async-virtual-scroll v-model="enabled" :data="largeList" :item-size="60">
  <!-- template content -->
</async-virtual-scroll>

2. Dynamic Height Mode

When items have varying heights, use dynamic height mode:

<async-virtual-scroll v-model="enabled" :data="varyingHeightList" :min-item-size="40">
  <!-- template content -->
</async-virtual-scroll>

3. Disable Virtual Scrolling

Disable virtual scrolling for small datasets:

<async-virtual-scroll :data="list" :ban="list.length < 100">
  <!-- template content -->
</async-virtual-scroll>

4. Custom Buffer Zone

Adjust buffer sizes as needed:

<async-virtual-scroll :data="list" :buffer="[150, 300]">
  <!-- template content -->
</async-virtual-scroll>

Important Notes

  1. Must bind v-model

  2. Dynamic Height Mode Requirements

    • Must provide minItemSize property for initial height estimation
    • Component automatically detects and updates layout when item heights change
  3. Performance Optimization Suggestions

    • Prefer itemSize for fixed-height items
    • Set appropriate buffer values to balance performance and UX
    • Avoid complex computations in item templates
  4. Data Updates

    • Layout automatically updates when data changes
    • Render area automatically adjusts for significant data changes

Why?

Traditional rendering methods create all DOM elements at once for large datasets, causing:

  1. High Memory Usage: Thousands of DOM nodes consume significant memory
  2. Reduced Rendering Performance: Browser handles excessive layout and paint operations
  3. Interaction Lag: Noticeable stuttering during scrolling and user interactions

Asynchronous Virtual Scrolling solves these issues by:

  • 🚀 On-demand Rendering: Only renders elements in viewport
  • Deferred Calculation: Uses IntersectionObserver for async visibility detection
  • 🔄 Smart Buffering: Preloads elements outside viewport for smooth scrolling
  • 📊 Height Caching: Records rendered element heights to avoid recalculation

Demo

https://github.com/user-attachments/assets/b84d2e26-de03-4e89-8f81-c0abb02aa8cc

License

MIT License