v-infinite-scroll

Bidirectional infinite-scroll component for Vue.js
12,531
Install
npm install v-infinite-scroll
Latest Version:1.0.4
License:MIT
Last Updated:Oct 11, 2017
Links: npm
Maintainer: dflourusso

v-infinite-scroll

Bidirectional infinite-scroll component for Vue.js

Installation

Using yarn

yarn add v-infinite-scroll

Using npm

npm i --save v-infinite-scroll

Demo

DEMO

Usage

Bundler (Webpack, Rollup)

import Vue from 'vue'

import InfiniteScroll from 'v-infinite-scroll'

// You need a specific loader for CSS files like https://github.com/webpack/css-loader
import 'v-infinite-scroll/dist/v-infinite-scroll.css'

Vue.use(InfiniteScroll)

Browser

<!-- Include after Vue -->
<link rel="stylesheet" href="v-infinite-scroll/dist/v-infinite-scroll.css"></link>
<script src="v-infinite-scroll/dist/v-infinite-scroll.js"></script>
<script>
  Vue.use(InfiniteScroll)
</script>

Example

<template>
  <v-infinite-scroll :loading="loading" @top="prevPage" @bottom="nextPage" :offset='20' style="max-height: 80vh; overflow-y: scroll;">
    <div v-for="item in items">{{item}}</div> // Your content
  </v-infinite-scroll>
</template>

<script>
export default {
  data () {
    return {
      page: 1,
      items: [],
      loading: false
    }
  },
  methods: {
    prevPage () {
      if (this.page == 1) return
      --this.page
      this.api()
    },
    nextPage () {
      ++this.page
      this.api()
    },
    api () {
      this.loading = true
      myApi.get({page: this.page}).then((response) => {
        this.items = response
        this.loading = false
      })
    }
  }
}
</script>

Properties

Name Type Required Default value Info
loading Boolean No Must be true if data is being loaded
offset Number No 0 Distance of top or bottom to emit the events
onTopScrollsToBottom Boolean No True When using bidirectional scroll, automatically scrolls to the bottom after load a previous page

Events

Name Info
top Triggered after the scroll arrives at the top
bottom Triggered after the scroll arrives at the bottom

Author

Daniel Fernando Lourusso

License

This project is licensed under MIT License

Related Packages

vue-infinite-scroll

An infinite scroll directive for vue.js.

1,283,113 2,853
vue3-infinite-list

An infinite scrolling list of vue3, of course vue2 can also be used.

7,005 242
vue-data-loading

Another component for infinite scroll and pull down/up to load data.

2,975 63
vue-scroll-bar

a simple custom scrollbar vue component

6,460 11

Version History

Version Released License
1.0.4 MIT
1.0.3 MIT
1.0.2 MIT
1.0.1 MIT