vue-super-scroller

npm npm vue2

Table of contents

Installation

npm install vue-scroller-dm --save

Global Install

Install all the components:

import Vue from 'vue'
import VueSuperScroller from 'vue-scroller-dm'

Vue.use(VueSuperScroller)

Usage

:load-disabled="!hasNext"

:on-refresh="refresh"

:on-load='loadMore'

Example

<template>
  <div id="app">
    <vue-scroller :load-disabled="!hasNext" :on-refresh="refresh" :on-load='loadMore'>
      <li v-for="(item,index) in lists">{{item}}</li>
    </vue-scroller>
  </div>
</template>

<script>
  export default {
    name: 'app',
    components: {},
    data () {
      return {
        lists: [1, 2, 3],
        hasNext: true
      }
    },
    mounted () {
      this.$nextTick(function () {
        this.loadMore()
      })
    },
    methods: {
      getRandArr (num = 20) {
        let arr = []
        for (let i = num - 1; i >= 0; i--) {
          arr.push(Math.round(Math.random() * 100))
        }
        return arr
      },

      refresh (call) {
        setTimeout(() => {
          this.lists = [1, 2, 3]
          call(true)
        }, 1000)
      },

      loadMore () {
        setTimeout(() => {
          this.lists = this.lists.concat(this.getRandArr(20))
          if (this.lists.length > 50) {
            this.hasNext = false
          }
        }, 1000)
      }
    }
  }
</script>

<style>
  #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
  }

  li {
    height: 150px;
    text-align: center;
    line-height: 150px;
    font-size: 30px;
  }

  li:nth-child(odd) {
    background-color: #eee
  }
</style>

License

MIT