• Stars
    star
    224
  • Rank 177,792 (Top 4 %)
  • Language
    TypeScript
  • Created over 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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 or set the initial scroll offset
  • Supports fixed or variable heights/widths
  • Vertical or Horizontal lists

see full examples on this demo.

Getting Started

Using npm:

npm install vue3-infinite-list --save

Using yarn:

yarn add vue3-infinite-list

Import vue Infinite list module into your app module

import InfiniteList from '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 }">
    <div class="li-con">{{ index + 1 }} : {{ item }}</div>
  </InfiniteList>

The default direction is vertical

Basic Usage: Fixed Height, Scroll Vertical(default)

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

The default direction is vertical

Scroll Direction: Horizontal

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

Dynamic Height

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

where getItemSize 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 }"
  >
    <div class="li-con" :class="getClass(index)">item{{ index + 1 }} : {{ item }}</div>
  </InfiniteList>

you can also use prop scrollToIndex 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 }"
    >
      <div class="li-con" :class="getClass(index)">item{{ index + 1 }} : {{ item }}</div>
    </InfiniteList>

you can also use prop scrollToIndex with scrollToAlignment 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-row class="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-button type="primary">Primary</el-button> <el-button type="success">Success</el-button></el-col
      >
    </el-row>
  </InfiniteList>

you can also use prop scrollOffset 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-row class="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-button type="primary">Button</el-button>
        <el-button type="success">Button</el-button>
      </el-col>
    </el-row>
  </InfiniteList>

just change the bind data dynamic.

Set overscanCount

    <InfiniteList :data="data" :width="'100%'" :height="500" :itemSize="60" :debug="debug" v-slot="{ item, index }" :overscanCount="2">
      <el-row class="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-button type="primary">Button</el-button>
          <el-button type="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

Property Type Required? Description
width Number or String* Width of List. This property will determine the number of rendered items when scrollDirection is 'horizontal'.
height Number or String* Height of List. This property will determine the number of rendered items when scrollDirection is 'vertical'.
data any[] The data that builds the templates within the Infinite scroll.
itemSize (index: number): number Either 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
scrollDirection String Whether the list should scroll vertically or horizontally. One of 'vertical' (default) or 'horizontal'.
scrollOffset Number Can be used to control the scroll offset; Also useful for setting an initial scroll offset
scrollToIndex Number Item index to scroll to (by forcefully scrolling if necessary)
scrollToAlignment String Used in combination with scrollToIndex, 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 specified scrollToIndex item is fully visible.
overscanCount Number Number 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 when scrollDirection is 'vertical'. Similarly, Height may only be a string if scrollDirection is 'horizontal'

Reporting Issues

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

Acknowledgments

This library is transplanted from react-tiny-virtual-list and react-virtualized. Thanks for the great works of author Claudéric Demers ❤️

License

is available under the MIT License.

More Repositories

1

TNT-Weekly

🙈 🙉 🙊 每周为您推荐国内外前端领域最新的优秀文章以及行业进展
5,158
star
2

FFCreator

A fast video processing library based on node.js (一个基于node.js的高速视频制作库)
JavaScript
2,816
star
3

awesome-blackmagic

🎭 ♠♥奇技淫巧 💠黑魔法大集合♦♣ 👺
1,027
star
4

wp2vite

一个让webpack项目支持vite的前端项目的转换工具。A front-end project automatic conversion tool。
JavaScript
709
star
5

shida

《视搭》是一个视频可视化搭建项目。您可以通过简单的拖拽方式快速生产一个短视频,使用方式就像易企秀或Maka 等 h5 搭建工具一样的简单,仅抛砖引玉希望您喜欢。
Vue
569
star
6

FEDiagram

图说前端>>收集各种前端技术图谱 🚕🚖🚗🚚🚛🚜
440
star
7

csijs

CSI.JS是一个特别的前端日志系统,帮你快速重建犯罪现场。
JavaScript
275
star
8

bbo

bbo is a utility library of zero dependencies for javascript. 🍖🌭🍔
JavaScript
275
star
9

limu

High performance immutable lib alternative to immer with the same api, based on shallow copy on read and mark modified on write mechanism.
JavaScript
217
star
10

awesome-state

collection of state management lib
187
star
11

transx

一个小巧玲珑的 vue 组件切换动画库, 支持 20 几种动画切换方式
JavaScript
183
star
12

clean-state

🐻 A pure and compact state manager, using React-hooks native implementation, automatically connect the module organization architecture. 🍋
TypeScript
120
star
13

tntweb-admin

react admin management system template
CSS
38
star
14

awesome-ffcreator

awesome ffcreator projects
30
star
15

jscalpel

A small feature library that makes it easier to manipulate objects
JavaScript
27
star
16

manage-table

对antd的table进行扩展,支持配置展示列
JavaScript
13
star
17

data-filler

make your backend response data shape reliable, with data-filler you can stay away from optional chain
JavaScript
2
star
18

html3canvas

html convert to canvas
TypeScript
1
star
19

hel

a solution of using micro module for frontend development
TypeScript
1
star