Giter Site home page Giter Site logo

tnfe / vue3-infinite-list Goto Github PK

View Code? Open in Web Editor NEW
216.0 8.0 33.0 775 KB

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

Home Page: https://tnfe.github.io/vue3-infinite-list

HTML 4.20% TypeScript 53.76% Vue 40.12% JavaScript 1.91%
vue-infinite-list infinite-list vue-infinite-scroll infinite

vue3-infinite-list's Introduction

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.

vue3-infinite-list's People

Contributors

adajuly avatar dependabot[bot] avatar drawcall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue3-infinite-list's Issues

README.zh-CN.md 中文翻译有问题

README.zh-CN.md 中文翻译有问题,这不叫无限滚动加载库吧,本身没有判断滚动到底后的加载事件,需要额外编写监听滚动事件进行加载。最多叫无限列表。

盒子高度超过26843542像素问题

如果渲染一千万条数据,整个盒子高度会很大,但实际盒子最大高度只能到26843542像素,就可能会造成滚到底部依然无法渲染后面的数据的问题。

完全自动化的高度有计划吗

列表项的高度完全由实际渲染决定,不再设置(itemSize)之类任何的有关高度的设置。完全预估形式的,这样比itemSize来的更加有特色。可能性能上稍逊。
ps:可以参考这个库的预估高度思路

how to use inside of nested v-for ?

                <div v-for="(col, iCol) in dl.lst" :key="iCol class="col c2  h-[168px]    text-center  " ">
                    <div class="cell border-b border-slate-500 w-[26px] h-[26px]    text-center overflow-hidden "
                        v-for="(c, iRow) in col" :key="iRow">

                        <img v-if="c >= 100" :src="'/static/img/dl-' + c + '.png'" alt=""
                            class="h-[100%] w-full  align-center p-[2px] ">

                    </div>
                </div>

Dyanmic data bug

Dynamic data seems to not be 100%.

Let's say I have a list of 10000 items, and a search bar.

I start typing in search bar, which shrinks my data to say 100 items. Vue3-infinite-list crashes with:

Uncaught (in promise) Error: Requested index 28 is outside of range 0..28
at SizeAndPosManager.getSizeAndPositionForIndex (vue3-infinite-list.es.js:90:1)
at Proxy.getItemStyle (vue3-infinite-list.es.js:344:39)
at vue3-infinite-list.es.js:524:32
at renderList (runtime-core.esm-bundler.js:6497:1)
at Proxy._sfc_render (vue3-infinite-list.es.js:521:70)
at renderComponentRoot (runtime-core.esm-bundler.js:893:1)
at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:5098:1)
at ReactiveEffect.run (reactivity.esm-bundler.js:167:1)
at updateComponent (runtime-core.esm-bundler.js:4968:1)
at processComponent (runtime-core.esm-bundler.js:4901:1)

I think the logic needs to be adjusted to deal with being scrolling past the end of the data?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.