1.0.10 • Published 6 years ago

v-scrolljs v1.0.10

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

v-scrolljs

Infinite scroll list for Vue.js.

Demo

Installation

npm install -S v-scrolljs

Import

import VScrolljs from 'v-scrolljs'
import 'v-scrolljs/dist/static/css/v-scrolljs.css'

export default {
  ...
  components: {
    scroll: VScrolljs,
  },
  ...
}

Usage

<template>
  <div>
    ...
      <scroll :list="items" :fetch="fetchItem" :total="page.total" :offsetItems="30">
          <template slot="tombstone" slot-scope="props">
              <div style="height: 50px;">loading....</div>
          </template>

          <template slot="item" slot-scope="props">
              <div style="border-bottom: 1px solid #eee;padding:10px 20px;word-break: break-all;">
                  <b>{{props.index}}&nbsp;&nbsp;</b>
                  <span>{{props.data}}</span>
              </div>
          </template>
          <template slot="bottom">
                All loaded
          </template>
      </scroll>
    ...
  </div>
</template>

<script>
import VScrolljs from 'v-scrolljs.js'
import 'v-scrolljs/dist/static/css/v-scrolljs.css'
const MESSAGES = [
    'data1',
    'data2',
    'data3',
]
export default {
    name: 'App',
    components: {
        scroll: VScrolljs
    },
    data () {
        return {
            items: [],
            page: {
                total: 3,
                pageSize: 200,
                pageNumber: 1
            }
        }
    },
    methods: {
        fetchItem () {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    const items = MESSAGES.slice(this.items.length, this.items.length + this.page.pageSize)
                    for (var i = 0; i < items.length; i++) {
                        this.items.push(items[i])
                    }
                    resolve()
                }, 300)
            })
        }
    }
}
</script>

Options

DirectiveTypeDefault
listArrayrequiredList of items
totalNumber1The number of total list
offsetItemsNumber20Number of additional nodes loaded outside the visual area
fetchFunctionfalseThe function of loading more items(async function)
resizeBooleanfalserecalculate the height of each item When the resize event is triggered
itemHeightNumber0Setting each item to the same height will reduce unnecessary calculations.

Development

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build
1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago