首页 > 其他分享 >vue 监听页面的滚动到页面底部

vue 监听页面的滚动到页面底部

时间:2023-01-18 15:24:06浏览次数:48  
标签:body vue page scrollTop document 监听 scrollHeight 页面

HTML
 <div class="moredata" v-if="loading"><van-loading size="24px">加载中...</van-loading></div>
 <div class="moredata" v-if="fineshed">{{moredata}}</div>
 
DATA
   loading: false,
      fineshed: false,
      page: 1,
      page_total: '',
      rows: 10,
      goodsarea: 8,
      goodsList: [],
      moredata: '没有更多了'
JS
mounted () {
    const _this = this
    window.onscroll = function () {
      // 变量scrollTop是滚动条滚动时,距离顶部的距离
      var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
      // 变量windowHeight是可视区的高度
      var windowHeight = document.documentElement.clientHeight || document.body.clientHeight
      // 变量scrollHeight是滚动条的总高度
      var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight
      // 滚动条到底部的条件
      if (scrollTop + windowHeight === scrollHeight) {
        _this.loading = true
        if (_this.page <= _this.page_total) {
            _this.page += 1 // 页数+1
  // 重新加载数剧
            _this.gethomegoods()
        }
        // 数据全部加载完成
        if (_this.page > _this.page_total) {
          _this.loading = false
          _this.finished = true
        }
      }
    }
  }
好文要顶 

标签:body,vue,page,scrollTop,document,监听,scrollHeight,页面
From: https://www.cnblogs.com/hxy--Tina/p/17059877.html

相关文章

  • vue关于通过下标更改数组的理解
    案例1:通过下标更改数组失败<template><div><el-button@click="handlerMe2">改变arr</el-button><div>{{arr}}--arr</div></div></template><s......
  • vue h5 扫码功能
    npminstall@zxing/library--save"@zxing/library":"^0.19.1",<template><div><fixed-nav-bar@clickLeft="goBack"leftText="扫一扫"></fixed-na......
  • Vue学习笔记
     Vue基础前置知识HTML+CSS+JavaSricpt+WebAPI(DOM+BOM)+Ajax创建Vue<script>newVue({  el:'#app',  data:{    message:'<h1>菜鸟教程<......
  • 前端框架对比总结(表格):React、Angular、Vue.js(国产)等
    前端框架对比前端框架优点缺点ReactReact是由Facebook开发和创建的开源框架。根据StackOverflowDeveloper的2021年调查,该框架是2022年最好的UI......
  • HBuilderX中 .vue解析
    1.<template>ui设计所有的有关界面的都写在这个里面2.<view>子标签,写在template中,view之间可以嵌套3.<script>js业务代码所有有关业务代码的都写在这个里面4.expoe......
  • VUEX 使用学习四 : action
    转载请注明出处:action用于处理异步任务;action,可以操作任意的异步操作,类似于mutations,但是是替代mutations来进行异步操作的。首先mutations中必须是同步方法,如果使用......
  • vue基本知识回顾 | this.$http.get 和 this.$http.post传参 / created与mounted区别 /
    vue基本知识回顾|this.$http.get和this.$http.post传参/created与mounted区别/富文本解析https://blog.csdn.net/feng2qing/article/details/126241834vue使......
  • 学习Vuex mutations
     Vuex中store数据改变的唯一方法就是提交 mutations。mutations里面装着一些改变数据方法的集合,这是Vuex设计很重要的一点,就是把处理数据逻辑方法全部放在 mutation......
  • vue中实现高德 地图定位功能
    index.html<template><divid="app"><divid="container"></div><div><p>经度:{{location.lng}}</p><p>纬度:{{location.lat}}</p>......
  • vuex详解
    vuex的介绍vuex是vue.js应用程序中的状态管理模式,它是集中式存储管理所有组件的数据状态,vuex解决了多个视图之间的数据交互同步,不需要进行组件连接再传递数据。vuex的5大......