zoukankan      html  css  js  c++  java
  • vue-触底加载更多

    方法一:插件 vue-infinite-scroll

    <template>
      <div>
        <div class="demo1" v-for="index of count" :key="index">
          demo
        </div>
        <div 
          v-infinite-scroll="loadMore" 
          infinite-scroll-disabled="busy" 
          infinite-scroll-distance="410">
        </div>
      </div>
    </template>
    
    <script>
    // infinite-scroll-disabled控制是否
    // infinite-scroll-distance 距离底部多少出发
    import infiniteScroll from 'vue-infinite-scroll'
    export default {
      name:'demo',
      data(){
        return{
          count:50,
          busy:false
        }
      },
      directives: {
        infiniteScroll
      },
      methods:{
        loadMore(){
          this.busy=true
          setTimeout(()=>{  
            this.count=this.count+50
            this.busy=false
          },2000)
        }
      }
    }
    </script>
    
    
    <style lang="scss" scoped>
    .demo1{
      height: 30px;
    }
    </style>

    方法二:封装一个方法

    const scroll={
        isEnd:false,
        start(callback){
            let timer=null
            callback && window.addEventListener('scroll',()=>{
                if(timer){
                    clearTimeout(timer)
                }
                //函数防抖动
                timer=setTimeout(()=>{
                    //游览器向上滚动的高度
                    const scrollTop=document.documentElement.scrollTop
                    //文档真实的高度
                    const scrollHeight=document.documentElement.scrollHeight
                    //游览器窗口(文档)的可是高度,就是肉眼可见的那部分真实高度
                    const clientHeight=document.documentElement.clientHeight
                    if(!this.isEnd && scrollHeight===scrollTop+clientHeight){
                        window.scrollTo(0,scrollTop-100)
                        callback()
                    }
                },300)
            })
        },
        end(){
            this.isEnd=true
        }
    }
    
    export default scroll

    使用

    import scroll from '@/utils/scroll.js';

    scroll.start(this.getList)

    方法三:在某个容器中触底事件

    document.getElementById('div').onscroll=()=>{ }
  • 相关阅读:
    redhat下设置网桥br0
    RackSpace推开源云计算平台OpenStack震动业界
    centos5.2 64位yum国内源之首选 上海交大(未验证)
    image config
    编程的四种境界
    怎样学好C语言
    利用SSL加密HTTP通道加强IIS安全性
    Sql Server 日期函数
    如何启用Oracle 11g的默认用户Scott
    ASP.NET自定义错误处理页面的添加
  • 原文地址:https://www.cnblogs.com/lxz-blogs/p/12768733.html
Copyright © 2011-2022 走看看