移动端下拉刷新、上拉加载之vueScroll

移动端开发,处理列表翻页和数据的时候,下拉刷新和上拉加载应用的比较普遍,今天给你们推荐一个vue的插件,vueScroll,首先上图:html

图片描述

话很少说,上代码了:vue

1、引入并使用VueScrollthis

import VueScroller from 'vue-scroller';
Vue.use(VueScroller)

2、在html或者.vue组件里面使用spa

clipboard.png

3、在js文件里面操做插件插件

首先在在methods里面写上方法code

clipboard.png

在data里面实现申明好 isLoading = true;htm

而后继续在methods里面写上刷新和加载的方法:blog

refresh(done) {
    let timer = null;
    this.page = 1;
    clearTimeout(timer);
    timer = setTimeout(() => {
         this.myInstalHomeFun(done);
    }, 500);
},
infinite(done) {
    let timer = null;
    clearTimeout(timer);
    timer = setTimeout(() => {
         this.myInstalHomeFun(done);
    }, 500);
}

到这里就能够实现效果了,可是可是 有几个细节我必须提一下图片

(1)高度的问题,这个插件须要给外层的scroller 设置高度,因此要注意,我这里是这样操做的:ip

methods: {
        // 获取高度
        getHeight(){
            let bodyHeight = document.documentElement.clientHeight;
            let scroller = this.$refs.scroller;
            let scrollerTop = scroller.getBoundingClientRect().top;
            scroller.style.height = (bodyHeight-scrollerTop)+"px";
        },
}

而且在mounted里面调用这个方法,这样就能够把高度设置好,而且在任何位置均可以放置了

(2)vueScoller 内部的结构是绝对定位,因此必定要给外层设置好相对定位;

clipboard.png

clipboard.png

这样就能够解觉定位引发的位置跑偏的问题了。

参考文档:https://vuescrolljs.yvescodin...

相关文章
相关标签/搜索