Convert Figma logo to code with AI

tangbc logovue-virtual-scroll-list

⚡️A vue component support big amount data list with high render performance and efficient.

4,384
592
4,384
77

Top Related Projects

⚡️ Blazing fast scrolling for any amount of data

The most powerful virtual list component for React

React components for efficiently rendering large lists and tabular data

React components for efficiently rendering large lists and tabular data

Quick Overview

Vue Virtual Scroll List is a lightweight and efficient component for Vue.js that enables virtual scrolling for large lists. It renders only the visible items in the viewport, significantly improving performance and memory usage when dealing with extensive data sets.

Pros

  • Improved performance for rendering large lists
  • Supports both fixed and variable height items
  • Compatible with Vue 2 and Vue 3
  • Customizable with various props and events

Cons

  • Learning curve for proper implementation
  • May require additional setup for complex list items
  • Limited documentation for advanced use cases
  • Potential issues with dynamic content height changes

Code Examples

  1. Basic usage with fixed height items:
<template>
  <virtual-list
    :data-key="'id'"
    :data-sources="items"
    :data-component="ItemComponent"
    :estimate-size="50"
  />
</template>

<script>
import VirtualList from 'vue-virtual-scroll-list'
import ItemComponent from './ItemComponent.vue'

export default {
  components: { VirtualList },
  data() {
    return {
      items: [/* ... */],
    }
  }
}
</script>
  1. Using variable height items:
<template>
  <virtual-list
    :data-key="'id'"
    :data-sources="items"
    :data-component="ItemComponent"
    :estimate-size="getEstimateSize"
  />
</template>

<script>
export default {
  // ...
  methods: {
    getEstimateSize(item) {
      return item.type === 'large' ? 100 : 50
    }
  }
}
</script>
  1. Implementing infinite scroll:
<template>
  <virtual-list
    :data-key="'id'"
    :data-sources="items"
    :data-component="ItemComponent"
    :estimate-size="50"
    @tobottom="loadMore"
  />
</template>

<script>
export default {
  // ...
  methods: {
    loadMore() {
      // Fetch more items and append to this.items
    }
  }
}
</script>

Getting Started

  1. Install the package:

    npm install vue-virtual-scroll-list
    
  2. Import and use the component in your Vue file:

    <template>
      <virtual-list
        :data-key="'id'"
        :data-sources="items"
        :data-component="ItemComponent"
        :estimate-size="50"
      />
    </template>
    
    <script>
    import VirtualList from 'vue-virtual-scroll-list'
    import ItemComponent from './ItemComponent.vue'
    
    export default {
      components: { VirtualList },
      data() {
        return {
          items: [/* Your list items */],
        }
      }
    }
    </script>
    
  3. Create an ItemComponent.vue file to define the appearance of each list item.

Competitor Comparisons

⚡️ Blazing fast scrolling for any amount of data

Pros of vue-virtual-scroller

  • More feature-rich, including support for dynamic item sizes and grid layouts
  • Better documentation and examples
  • Active development and maintenance

Cons of vue-virtual-scroller

  • Slightly more complex API, which may have a steeper learning curve
  • Potentially higher memory usage due to additional features

Code Comparison

vue-virtual-scroll-list:

<virtual-list :data-key="'id'" :data-sources="items" :data-component="itemComponent" />

vue-virtual-scroller:

<RecycleScroller
  class="scroller"
  :items="items"
  :item-size="32"
  key-field="id"
  v-slot="{ item }"
>
  <div class="user">{{ item.name }}</div>
</RecycleScroller>

The code comparison shows that vue-virtual-scroller uses a more declarative approach with its RecycleScroller component, allowing for inline templates. vue-virtual-scroll-list, on the other hand, requires a separate component to be passed as a prop.

Both libraries offer efficient virtual scrolling for large lists in Vue applications. vue-virtual-scroller provides more advanced features and better documentation, making it suitable for complex use cases. vue-virtual-scroll-list has a simpler API, which may be preferable for basic implementations or developers new to virtual scrolling concepts.

The most powerful virtual list component for React

Pros of react-virtuoso

  • More comprehensive feature set, including grid layouts and grouped lists
  • Better TypeScript support and type definitions
  • More active development and frequent updates

Cons of react-virtuoso

  • Steeper learning curve due to more complex API
  • Larger bundle size, which may impact performance for smaller projects

Code Comparison

react-virtuoso:

<Virtuoso
  style={{ height: '400px' }}
  totalCount={1000}
  itemContent={index => <div>Item {index}</div>}
/>

vue-virtual-scroll-list:

<virtual-list
  :size="40"
  :remain="8"
  :bench="20"
  :itemcount="1000"
>
  <item v-for="index in 1000" :key="index" :index="index" />
</virtual-list>

Summary

react-virtuoso offers a more feature-rich solution with better TypeScript support and active development. However, it may have a steeper learning curve and larger bundle size compared to vue-virtual-scroll-list. The code examples show that react-virtuoso has a more concise API, while vue-virtual-scroll-list requires more configuration props. Both libraries effectively handle virtual scrolling, but react-virtuoso may be better suited for larger, more complex projects, while vue-virtual-scroll-list could be a simpler option for Vue.js applications with basic virtualization needs.

React components for efficiently rendering large lists and tabular data

Pros of react-window

  • More comprehensive documentation and examples
  • Supports both fixed-size and variable-size lists and grids
  • Actively maintained with frequent updates

Cons of react-window

  • React-specific, not suitable for Vue.js projects
  • Steeper learning curve for complex implementations
  • Limited built-in features compared to vue-virtual-scroll-list

Code Comparison

react-window:

import { FixedSizeList } from 'react-window';

const Example = () => (
  <FixedSizeList
    height={400}
    itemCount={1000}
    itemSize={35}
    width={300}
  >
    {({ index, style }) => (
      <div style={style}>Row {index}</div>
    )}
  </FixedSizeList>
);

vue-virtual-scroll-list:

<template>
  <virtual-list
    :data-key="'id'"
    :data-sources="items"
    :data-component="itemComponent"
    :estimate-size="50"
  />
</template>

<script>
import VirtualList from 'vue-virtual-scroll-list'

export default {
  components: { VirtualList },
  // ...
}
</script>

Both libraries provide efficient rendering of large lists, but react-window offers more flexibility in terms of list types and sizing options. vue-virtual-scroll-list is more straightforward to implement in Vue.js projects and includes some additional features out of the box. The choice between the two largely depends on the framework being used and the specific requirements of the project.

React components for efficiently rendering large lists and tabular data

Pros of react-virtualized

  • More comprehensive set of components for virtualization (List, Grid, Table, etc.)
  • Better documentation and examples
  • Larger community and more frequent updates

Cons of react-virtualized

  • Steeper learning curve due to more complex API
  • Larger bundle size, which may impact performance for smaller applications
  • React-specific, limiting its use in other frameworks

Code Comparison

vue-virtual-scroll-list:

<virtual-list
  :data-key="'id'"
  :data-sources="items"
  :data-component="ItemComponent"
  :estimate-size="50"
/>

react-virtualized:

<List
  width={300}
  height={300}
  rowCount={items.length}
  rowHeight={50}
  rowRenderer={({ index, key, style }) => (
    <div key={key} style={style}>
      {items[index].name}
    </div>
  )}
/>

Both libraries aim to improve performance when rendering large lists, but react-virtualized offers a more feature-rich solution at the cost of increased complexity. vue-virtual-scroll-list provides a simpler API, making it easier to implement for basic use cases in Vue applications. The choice between the two depends on the specific project requirements, framework preference, and desired level of customization.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

CIStatus Downloads Version Quality

Table of contents

Advantages

  • Only 3 required props, simple and very easy to use.

  • Big data list with high render performance and efficient.

  • You don't have to care about item size, it will calculate automatic.

Live demo

https://tangbc.github.io/vue-virtual-scroll-list

https://codesandbox.io/s/live-demo-virtual-list-e1ww1

Simple usage

npm install vue-virtual-scroll-list --save

Root component:

<template>
  <div>
    <virtual-list style="height: 360px; overflow-y: auto;" // make list scrollable
      :data-key="'uid'"
      :data-sources="items"
      :data-component="itemComponent"
    />
  </div>
</template>

<script>
  import Item from './Item'
  import VirtualList from 'vue-virtual-scroll-list'

  export default {
    name: 'root',
    data () {
      return {
        itemComponent: Item,
        items: [{uid: 'unique_1', text: 'abc'}, {uid: 'unique_2', text: 'xyz'}, ...]
      }
    },
    components: { 'virtual-list': VirtualList }
  }
</script>

Item component:

<template>
  <div>{{ index }} - {{ source.text }}</div>
</template>

<script>
  export default {
    name: 'item-component',
    props: {
      index: { // index of current item
        type: Number
      },
      source: { // here is: {uid: 'unique_1', text: 'abc'}
        type: Object,
        default () {
          return {}
        }
      }
    }
  }
</script>

More usages or getting start you can refer to these clearly examples.

Props type

Required props

             Prop             TypeDescription
data-keyString|FunctionThe unique key get from data-sources in each data object. Or a function called with each data-source and return their unique key. Its value must be unique in data-sources, it is used for identifying item size.
data-sourcesArray[Object]The source array built for list, each array data must be an object and has an unique key get or generate for data-key property.
data-componentComponentThe render item component created / declared by vue, and it will use the data object in data-sources as render prop and named: source.

Optional props

Commonly used

           Prop            Type Default Description
keeps Number 30 How many items you are expecting the virtual list to keep rendering in the real dom.
extra-props Object {} Extra props assign to item component that are not in data-sources. Notice: index and source are both occupied inner.
estimate-size Number 50 The estimate size of each item, if it is closer to the average size, the scrollbar length looks more accurately. It is recommended to assign the average that calculate by yourself.
Uncommonly used

               Prop                Type Default Description
start Number 0 Setting scroll position stay start index.
offset Number 0 Setting scroll position stay offset.
scroll Event Emited when scrolling, param (event, range).
totop Event Emited when scrolled to top or left, no param.
tobottom Event Emited when scrolled to bottom or right, no param.
resized Event Emited when item resized (mounted), param (id, size).
direction String vertical Scroll direction, available values are vertical and horizontal
page-mode Boolean false Let virtual list using global document to scroll through the list.
top-threshold Number 0 The threshold to emit totop event, attention to multiple calls.
bottom-threshold Number 0 The threshold to emit tobottom event, attention to multiple calls.
root-tag String div Root element tag name.
wrap-tag String div List wrapper element (role=group) tag name.
wrap-class String List wrapper element class name.
wrap-style Object {} List wrapper element inline style.
item-tag String div Item wrapper element (role=item) tag name.
item-class String Item wrapper element class name.
item-class-add Function A function that you can return extra class (String) to item wrapper element, param (index).
item-style Object {} Item wrapper element inline style.
item-scoped-slots Object {} The $scopedSlots for item component.
header-tag String div For using header slot, header slot wrapper element (role=header) tag name.
header-class String For using header slot, header slot wrapper element class name.
header-style Object {} For using header slot, header slot wrapper element inline style.
footer-tag String div For using footer slot, footer slot wrapper element (role=footer) tag name.
footer-class String For using footer slot, footer slot wrapper element class name.
footer-style Object {} For using using footer slot, footer slot wrapper element inline style.

Public methods

Usefull public methods

You can call these methods via ref:

Method Description
reset() Reset all state back to initial.
scrollToBottom() Manual set scroll position to bottom.
scrollToIndex(index) Manual set scroll position to a designated index.
scrollToOffset(offset) Manual set scroll position to a designated offset.
getSize(id) Get the designated item size by id (from data-key value).
getSizes() Get the total number of stored (rendered) items.
getOffset() Get current scroll offset.
getClientSize() Get wrapper element client viewport size (width or height).
getScrollSize() Get all scroll size (scrollHeight or scrollWidth).
updatePageModeFront() When using page mode and virtual list root element offsetTop or offsetLeft change, you need call this method manually.

Attentions

This component use an in-place patch strategy to render list instead of v-for and :key. This way achieves the best efficient, but only suitable when your list output does not rely on item component inner state or temporary DOM state (e.g. form input values).

But how to deal with such a situation? Without maintaining inner state, recommend to use props and dispatch (stateless component), here is an example keep-state.

Contributions

Welcome to improve this component with any issue, pull request or code review.

Changelogs

Maintain and update occasionally, for changes see release.

License

MIT License.

NPM DownloadsLast 30 Days