Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-virtual-scroll-list

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-virtual-scroll-list

A vue component support big amount data list with high scroll performance.

  • 2.3.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
117K
decreased by-8.91%
Maintainers
1
Weekly downloads
 
Created
Source

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           TypeDefaultDescription
keepsNumber30How many items you are expecting the virtual list to keep rendering in the real dom.
extra-propsObject{}Extra props assign to item component that are not in data-sources. Notice: index and source are both occupied inner.
estimate-sizeNumber50The 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               TypeDefaultDescription
startNumber0Setting scroll position stay start index.
offsetNumber0Setting scroll position stay offset.
scrollEventEmited when scrolling, param (event, range).
totopEventEmited when scrolled to top or left, no param.
tobottomEventEmited when scrolled to bottom or right, no param.
resizedEventEmited when item resized (mounted), param (id, size).
directionStringverticalScroll direction, available values are vertical and horizontal
page-modeBooleanfalseLet virtual list using global document to scroll through the list.
top-thresholdNumber0The threshold to emit totop event, attention to multiple calls.
bottom-thresholdNumber0The threshold to emit tobottom event, attention to multiple calls.
root-tagStringdivRoot element tag name.
wrap-tagStringdivList wrapper element (role=group) tag name.
wrap-classStringList wrapper element class name.
wrap-styleObject{}List wrapper element inline style.
item-tagStringdivItem wrapper element (role=item) tag name.
item-classStringItem wrapper element class name.
item-class-addFunctionA function that you can return extra class (String) to item wrapper element, param (index).
item-styleObject{}Item wrapper element inline style.
item-scoped-slotsObject{}The $scopedSlots for item component.
header-tagStringdivFor using header slot, header slot wrapper element (role=header) tag name.
header-classStringFor using header slot, header slot wrapper element class name.
header-styleObject{}For using header slot, header slot wrapper element inline style.
footer-tagStringdivFor using footer slot, footer slot wrapper element (role=footer) tag name.
footer-classStringFor using footer slot, footer slot wrapper element class name.
footer-styleObject{}For using using footer slot, footer slot wrapper element inline style.

Public methods

Usefull public methods

You can call these methods via ref:

MethodDescription
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.

Keywords

FAQs

Package last updated on 29 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc