Vue-loadmore - A pull-down refresh and pull-up loadmore scroll component for Vue.js

Overview

vuejs-loadmore

Npm Version Build Status

NPM

A pull-down refresh and pull-up loadmore scroll component for Vue.js.

Easy to use by providing simple api. Unlike other component libraries, it uses the browser itself to scroll instead of js, so it has a smaller code size but does not lose the user experience.

English | 中文

Preview

Online demo

You can also scan the following QR code to access the demo:

Installation

Install the npm package

# npm
npm install vuejs-loadmore --save

Import

import Vue from 'vue';
import VueLoadmore from 'vuejs-loadmore';

Vue.use(VueLoadmore);

Usage

Basic Usage

<vue-loadmore 
  :on-refresh="onRefresh" 
  :on-loadmore="onLoad"
  :finished="finished">
  <div v-for="(item, i) of list" :key="i"></div>
</vue-loadmore>

The on-refresh and on-loadmore will be Emitted when pull refresh or scroll to the bottom, you should need to execute the callback function done() after processing the data request.

If you don't need refresh, only not to bind on-refresh.

When the data request is finished, the data of finished you can changed to true, then will show finished-text.

export default {
  data() {
    return {
      list: [],
      page: 1,
      pageSize: 10,
      finished: false
    };
  },
  mounted() {
    this.fetch();
  },
  methods: {
    onRefresh(done) {
      this.list = [];
      this.page = 1;
      this.finished = false;
      this.fetch();

      done();
    },

    onLoad(done) {
      if (this.page <= 10) {
        this.fetch();
      } else {
        // all data loaded
        this.finished = true;
      }
      done();
    },

    fetch() {
      for (let i = 0; i < this.pageSize; i++) {
        this.list.push(this.list.length + 1);
      }
      this.page++;
    }
  },
}

Load Error Info

<vue-loadmore 
  :on-loadmore="onLoad"
  :finished="finished"
  :error.sync="error">
  <div v-for="(item, i) of list" :key="i"></div>
</vue-loadmore>
export default {
  data() {
    return {
      list: [],
      finished: false,
      error: false,
    };
  },
  methods: {
    onLoad() {
      fetchSomeThing().catch(() => {
        this.error = true;
      });
    },
  },
};

API

Props

Attribute Description Type Default
on-refresh Will be Emitted when pull refresh function -
pulling-text The Text when pulling in refresh string 下拉刷新
loosing-text The Text when loosing in refresh string 释放刷新
loading-text The Text when loading in refresh string 正在刷新
success-text The Text when loading success in refresh string 刷新完成
show-success-text Whether to show success-text boolean true
pull-distance The distance to trigger the refresh status number | string 50
head-height The height of the area of the refresh shows number | string 50
animation-duration Animation duration of the refresh number | string 200
on-loadmore Will be Emitted when scroll to the bottom function -
immediate-check Whether to check loadmore position immediately after mounted boolean true
load-offset The on-loadmore will be Emitted when the distance from the scroll bar to the bottom is less than the load-offset number | string 50
finished Whether the data is loaded boolean false
error Whether the data is loaded error, the on-loadmore will be Emitted only when error text clicked, the sync modifier is needed boolean false
loading-text The Text when loading in loaded string 正在加载
finished-text The Text when the data is loaded string 没有更多了
error-text The Text when error loaded string 请求失败,点击重新加载

Methods

Use ref to get List instance and call instance methods.

Name Description Attribute Return value
checkScroll Check scroll position - -

Example

You can see the demo for quickly understand how to use this package.

git clone [email protected]:staticdeng/vuejs-loadmore.git
yarn install
yarn example:dev
You might also like...
Scroll Picker Component for Vue2. Support All Gestures of Mouse(even also MouseWheel!) and Touch.

Scroll Picker Component for Vue2. Support All Gestures of Mouse(even also MouseWheel!) and Touch.

A vue directive that accepts a threshold value and a callback function that tells you if current scroll position is before the binded element, after element and inside the threshold or past the threshold

A vue directive that accepts a threshold value and a callback function that tells you if current scroll position is before the binded element, after element and inside the threshold, or past the threshold

Vue plugin that provides functionality for remembering scroll position and loaded items in a catalog page after navigating back and forth to a single item page, with customisable options.

Vue plugin that provides functionality for remembering scroll position and loaded items in a catalog page after navigating back and forth to a single item page, with customisable options.

The Simplest Scroll Area Component with custom scrollbar for Vue Js. https://bosnaufal.github.io/vue-scrollbar/

Vue Scrollbar The Simplest Scroll Area Component with custom scrollbar for Vue Js. All animation, Height and Width are pure CSS, So it's TOTALLY CUSTO

A Vue component that syncronize containers scroll positions

vue-scroll-sync A Vue component that syncronize containers scroll positions Installation npm i --save vue-scroll-sync Browser Include the script file,

A Back-to-top component for Vue.js, which scroll page to the top when clicked

Vue Backtotop Component A Back-to-top component for Vue.js, which scroll page to the top when clicked Demo See demo. Install via npm npm install vue-b

Lightweight package for highlighting menu items as you scroll the page, also scrolling to target section when item clicked. Use as a vue component/directive or in vanilla js.

navscroll-js Installation This package is available on npm. Using npm: npm install --save navscroll Using yarn: yarn add navscroll Directly include it

🎰 Scroll-in text component for Vue
🎰 Scroll-in text component for Vue

Scroll-in text component for Vue 'vue-scrollin' is a Vue component that scrolls through various characters on mount before revealing the correct text.

A scroll to top component for Vue 3
A scroll to top component for Vue 3

A scroll to top component for Vue 3

Comments
  • There are two props called 'loading-text'.

    There are two props called 'loading-text'.

    hi I have two questions :)

    One is Refreshing, the other is Loading. I want to use the two separately.

    and

    Is there any way to turn off infinite scroll?

    opened by wealways 1
  • ERROR in xxx.js from UglifyJs Unexpected token: name (hook)

    ERROR in xxx.js from UglifyJs Unexpected token: name (hook)

    When I use this component library, it runs normally local development, but an error is reported when using uglifyjs webpack plugin for webpack packaging.

    The following is the detailed error reporting information:

    ERROR in js/vendors.bc580846f352f4ad3188.js from UglifyJs Unexpected token: name (hook) [js/vendors.bc580846f352f4ad3188.js:56427,10] Child extract-text-webpack-plugin ../../../node_modules/extract-text-webpack-plugin/dist ../../../node_modules/css-loader/index.js!../../../node_modules/postcss-loader/lib/index.js??ref--1-3!../../../node_modules/less-loader/dist/cjs.js!../stylesheets/application.less:

    opened by weigong12 1
  • TypeError: Cannot read property 'getBoundingClientRect

    TypeError: Cannot read property 'getBoundingClientRect

    调用的时候为什么一直报这个错 "[Vue warn]: Error in nextTick: "TypeError: Cannot read property 'getBoundingClientRect' of undefined"\n\nfound in\n\n---> \n at src/xxx.vue\n at src/App.vue\n "

    opened by locdlocd 2
  • To bad I can not get this to work in Vue 3

    To bad I can not get this to work in Vue 3

    Trying to use this in Vue 3 gives errors about no default import from vue and once you work around that, it gives other errors about missing things as well.

    A proper example of how to use this in Vue 3 ( with