A VueJS 2.6 infinite scrolling component
- Lightweight (only ~ 4kb gzipped)
- Ultra high performance reusing DOM elements
- Support variable height
- Support any scrollable container (inside body)
npm install --save @bgds/infinite-scroller
You can install it globally from the default import:
import Vue from 'vue'
import scroller from '@bgds/infinite-scroller'
import from '@bgds/infinite-scroller/dist/infinite-scroller.cjs.css'
Vue.use(scroller)
Or locally using the named import:
import { InfiniteScroller } from '@bgds/infinite-scroller'
export default {
components: {
InfiniteScroller
}
}
Don't forget to import the css then:
@import '~@bgds/infinite-scroller/dist/infinite-scroller.cjs'
<infinite-scroller :items="items">
<template slot-scope="{ item }">{{ item }}</template>
</infinite-scroller>
❗️ | The component must be contained in (or be itself) a scrollable container by having a height and overflow with values scroll or auto |
---|
The component has a @load-more
event that is called when the scroll approaches it's end and property has-more
is set to true
. The payload sent by the event is the index of the first needed element (i.e. the size of the items
array):
<infinite-scroller :items="items" :has-more="hasMore" @load-more="loadMore">
<template slot-scope="{ item }">{{ item }}</template>
</infinite-scroller>
Prop | Type | Default | Description |
---|---|---|---|
items | Array | [] |
Array of items to be iterated on the list |
has-more | Boolean | false |
Flag to inform the container that there are more items to be loaded |
threshold | Number or Array | [50, 10] |
The number of items to be loaded before and after the ones visible on the list (if the value is a number, it will be converted to an array with the same number repeated twice) |
tag | String | "div" |
The tag name to be used for the container |
item-tag | String | "div" |
The tag name to be used for the items |
Event | Payload | Description |
---|---|---|
load-more | from: Number |
Called when the list is { threshold } items close to it's end. |
Slot name | Scope | Default | Description |
---|---|---|---|
default | { item: Any, index: number } |
- | each item being loaded on the list |
loading | - | Loading... | the item with a loading message at the end of the list |
- Fork this repository.
- Create new branch with feature name.
- Run
npm install
andnpm run play
. - Create your feature.
- Commit and set commit message with feature name and description.
- Push your code to your fork repository.
- Create pull request. 😃
This project is licensed under MIT License