Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

一个支持百万数量级的Vue3无限滚动列表组件

NotificationsYou must be signed in to change notification settings

tnfe/vue3-infinite-list

Repository files navigation

English |简体中文

A short and powerful infinite scroll list library for vue, with zero dependencies 💪

  • Tiny & dependency free – Only 3kb gzipped
  • Render millions of items, without breaking a sweat
  • Scroll to index orset the initial scroll offset
  • Supports fixed orvariable heights/widths
  • Vertical orHorizontal lists

see full examples on thisdemo.

Getting Started

Usingnpm:

npm install vue3-infinite-list --save

Usingyarn:

yarn add vue3-infinite-list

Import vue Infinite list module into your app module

importInfiniteListfrom'vue3-infinite-list';

Wrap Infinite list tag around list items

<InfiniteList:data="data":width="'100%'":height="500":itemSize="50":debug="debug"v-slot="{ item, index }"><divclass="li-con">{{ index + 1 }} : {{ item }}</div></InfiniteList>

The default direction isvertical

Basic Usage: Fixed Height, Scroll Vertical(default)

<InfiniteList:data="data":width="'100%'":height="500":itemSize="50":debug="debug"v-slot="{ item, index }"><divclass="li-con">{{ index + 1 }} : {{ item }}</div></InfiniteList>

The default direction isvertical

Scroll Direction: Horizontal

<InfiniteList:data="data":width="900":height="220":itemSize="115"scrollDirection="horizontal":debug="debug"v-slot="{ item, index }"><divclass="li-con li-con-r">      item{{ index }}<br/>      xxxxxxx<br/>      xxxxxxx<br/><el-buttontype="primary"round>Primary</el-button></div></InfiniteList>

Dynamic Height

<InfiniteList:data="data":width="'100%'":height="520":itemSize="getItemSize":debug="debug"v-slot="{ item, index }"><divclass="li-con">item {{ index }} : {{ item }}</div></InfiniteList>

wheregetItemSize is a function with it's signature as :(i: number): number, with this you can dynamic set your item height.

Scroll to Index

<InfiniteList:data="data":width="'100%'":height="500":itemSize="getItemSize":scrollToIndex="scrollToIndex":debug="debug"v-slot="{ item, index }"><divclass="li-con":class="getClass(index)">item{{ index + 1 }} : {{ item }}</div></InfiniteList>

you can also use propscrollToIndex to scroll to special index。

Scroll to Index (More fine-grained with Alignment)

<InfiniteList:data="data":width="'100%'":height="500":itemSize="getItemSize":scrollToIndex="scrollToIndex":scrollToAlignment="scrollToAlignment":debug="debug"v-slot="{ item, index }"><divclass="li-con":class="getClass(index)">item{{ index + 1 }} : {{ item }}</div></InfiniteList>

you can also use propscrollToIndex withscrollToAlignment to special how the item align to the container, which has four value:auto,start,center,end

Scroll to Offset

<InfiniteList:data="data":width="'100%'":height="500":itemSize="90":scrollOffset="scrollOffset":debug="debug"v-slot="{ item, index }"><el-rowclass="mb-4 li-con"><el-col:span="8">index: {{ index + 1 }}</el-col><el-col:span="8">xxxxxxxxxx</el-col><el-col:span="8"><el-buttontype="primary">Primary</el-button><el-buttontype="success">Success</el-button></el-col></el-row></InfiniteList>

you can also use propscrollOffset to scroll to special offset。

Dynamic Data is also Support

<InfiniteList:data="data":width="'100%'":height="500":itemSize="60":debug="debug"v-slot="{ item, index }"><el-rowclass="li-con"><el-col:span="6">item{{ index + 1 }}</el-col><el-col:span="6">2022-05-01</el-col><el-col:span="6">Name: Tom</el-col><el-col:span="6"><el-buttontype="primary">Button</el-button><el-buttontype="success">Button</el-button></el-col></el-row></InfiniteList>

just change the binddata dynamic.

Set overscanCount

<InfiniteList:data="data":width="'100%'":height="500":itemSize="60":debug="debug"v-slot="{ item, index }":overscanCount="2"><el-rowclass="li-con"><el-col:span="6">item{{ index + 1 }}</el-col><el-col:span="6">2022-05-01</el-col><el-col:span="6">Name: Tom</el-col><el-col:span="6"><el-buttontype="primary">Button</el-button><el-buttontype="success">Button</el-button></el-col></el-row></InfiniteList>

Number of extra buffer items to render above/below the visible items. Tweaking this can help reduce scroll flickering on certain browsers/devices.

Prop Types

PropertyTypeRequired?Description
widthNumber or String*Width of List. This property will determine the number of rendered items when scrollDirection is'horizontal'.
heightNumber or String*Height of List. This property will determine the number of rendered items when scrollDirection is'vertical'.
dataany[]The data that builds the templates within the Infinite scroll.
itemSize(index: number): numberEither a fixed height/width (depending on the scrollDirection), an array containing the heights of all the items in your list, or a function that returns the height of an item given its index:(index: number): number
scrollDirectionStringWhether the list should scroll vertically or horizontally. One of'vertical' (default) or'horizontal'.
scrollOffsetNumberCan be used to control the scroll offset; Also useful for setting an initial scroll offset
scrollToIndexNumberItem index to scroll to (by forcefully scrolling if necessary)
scrollToAlignmentStringUsed in combination withscrollToIndex, this prop controls the alignment of the scrolled to item. One of:'start','center','end' or'auto'. Use'start' to always align items to the top of the container and'end' to align them bottom. Use'center' to align them in the middle of the container.'auto' scrolls the least amount possible to ensure that the specifiedscrollToIndex item is fully visible.
overscanCountNumberNumber of extra buffer items to render above/below the visible items. Tweaking this can help reduce scroll flickering on certain browsers/devices.

* Width may only be a string whenscrollDirection is'vertical'. Similarly, Height may only be a string ifscrollDirection is'horizontal'

Reporting Issues

Found an issue? Pleasereport it along with any relevant details to reproduce it.

Acknowledgments

This library is transplanted fromreact-tiny-virtual-list andreact-virtualized.Thanks for the great works of authorClaudéric Demers ❤️

License

is available under the MIT License.

About

一个支持百万数量级的Vue3无限滚动列表组件

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp