html:

<div class="list" ref="scrollTopList">
<div class="listsmall" v-for="(item,index) of list" :key="index" @click="getDeviceInfo(item.id)">
<span class="state" :class="{'state1':item.status==1,'state0':item.status==0,'state2':item.status==2,'state3':item.status==3}"></span>
<span class="text textcolor">【{{item.code||item.name}}】</span>
<span class="text">{{item.name}}</span>
</div>
</div>

js:

先写滚动事件

handleScroll(){
let scrollTop = this.$refs.scrollTopList.scrollTop,
clientHeight = this.$refs.scrollTopList.clientHeight,
scrollHeight = this.$refs.scrollTopList.scrollHeight,
height = 50; //根据项目实际定义
if(scrollTop +clientHeight >= scrollHeight - height){
if(this.pageSize > this.total){
return false
}else{
this.pageSize = this.pageSize +10 //显示条数新增
this.getpageList() //请求列表list 接口方法
}
}else{
return false
}
},
 
 
method中写节流函数
throttle(func, wait) {
let lastTime = null
let timeout
return () => {
let context = this;
let now = new Date();
let arg = arguments;
if (now - lastTime - wait > 0) {
if (timeout) {
clearTimeout(timeout)
timeout = null
}
func.apply(context, arg)
lastTime = now
} else if (!timeout) {
timeout = setTimeout(() => {
func.apply(context, arg)
}, wait)
}
}
},
mounted中调用
mounted(){
this.$refs.scrollTopList.addEventListener("scroll",this.throttle(this.handleScroll,500),true)
},

//-------------------------------------------------------------------------------------------第二种写法

html:

添加滚动事件

<div class="tablelist-box" @scroll="scrollEvent($event)">
<div
class="tablelist"
:class="{'active':listDevicesDetailIndex==index}"
v-for="(item,index) of deviceList"
:key="index"
v-if="deviceList.length !== 0"
@click="deviceDetail(item,index)"
>
<span class="tablelist-status">
<i
:class="{zx:item.status==1,lx:item.status==2, wjh:item.status==0,gj:item.status==3}"
></i>
</span>
<span class="tablelist-bg">{{item.code != null ?item.code:"/"}}</span>
</div>
<div class="list-more" v-show="!deviceListIsFinish">{{deviceTip}}</div>
<div class="list-more" v-show="deviceListIsFinish">{{deviceTip}}</div>
</div>

css:

tablelist-box{
height: //根据实际项目取
overflow:auto //必须 不然判断有问题
}

css 定义

js

写入滚动事件

scrollEvent(e) {
if (e instanceof Event) {
let el = e.target;
let scrollTop = el.scrollTop;
// 获取可视区的高度
let clientHeight = el.clientHeight;
// 获取滚动条的总高度
let scrollHeight = el.scrollHeight;
let height = 50;
//到底了
// console.log(this.deviceListIsLoad, this.deviceListIsFinish);
// console.log(scrollTop, clientHeight, scrollHeight);
//是否继续加载且已完成加载
if (
scrollTop + clientHeight >= scrollHeight &&
this.deviceListIsLoad &&
!this.deviceListIsFinish
) {
// 把距离顶部的距离加上可视区域的高度 等于或者大于滚动条的总高度就是到达底部
this.deviceListIsLoad = true;
console.log("到底了");
setTimeout(() => {
this._deviceListPage();
}, 1000);
}
}

请求列表的处理

 _deviceListPage() {
let params = {
pageSize: this.devicePageSize,
pageNum: this.devicePageNum,
kw: "", //查询条件(通配查询条件)
type: this.deviceType, //设备类型(下拉)2.1.6接口获取
code: this.deviceCode, //设备编号
areaId: this.deviceareaId, //位置区域
status: this.deviceStatus, //状态 1:在线(正常),0:未激活,2已离线,3.告警
imei: "" //imei编号
};
deviceListPage(params).then(res => {
if (res.code == 200) {
this.devicePageTotal = res.body.total;
this.devicePageSize = res.body.pageSize;
this.devicePageNum = res.body.pageNum;
this.devicePageTotalPages = parseInt(
(this.devicePageTotal + this.devicePageSize - 1) /
this.devicePageSize
);
if (this.devicePageTotal == 0) {
// console.log("没有数据");
//没有数据
this.deviceListnodata = true;
this.deviceListIsLoad = false;
this.deviceListIsFinish = true;
this.devicePageNum = 1;
this.deviceTip = "暂无数据";
return false;
}
this.deviceList = this.deviceList.concat(res.body.datas);
// console.log(this.devicePageNum, this.devicePageTotalPages);
if (this.devicePageNum == this.devicePageTotalPages) {
//没有更多
this.deviceListIsLoad = false;
this.deviceListIsFinish = true;
this.devicePageNum = 1;
this.deviceTip = "没有更多了~";
// console.log("没有更多了");
} else {
// console.log("下一页");
//下一页
this.deviceListIsLoad = true;
this.deviceListIsFinish = false;
this.devicePageNum++;
this.deviceTip = "正在加载中~";
}
// console.log("deviceList", this.deviceList);
} else {
// this.deviceList = [];
this.deviceListIsLoad = false;
this.deviceListIsFinish = true;
this.devicePageNum = 1;
this.deviceTip = "数据加载失败~";
}
});
},

return中的定义

devicePageSize: 10, //每页显示
devicePageNum: 1, //当前页
devicePageTotal: 0, //总条数
devicePageTotalPages: 0, //总页数
deviceListIsFinish: false, //是否加载完成
deviceListIsLoad: false, //是否加载更多
deviceListnodata: false, //是否有数据
deviceTip: "",

pc端vue 滚动到底部翻页的更多相关文章

  1. 基于vue实现上下滑动翻页效果

    18年年底的时候,一直在做年度报告的H5页面,因为项目需要,需要实现上下滑动翻页,并且上滑的页面比正常页面的比例要缩小一定比例. 效果类似于http://www.17sucai.com/pins/de ...

  2. 转载 vue-awesome-swiper - 基于vue实现h5滑动翻页效果

    说到h5的翻页,很定第一时间想到的是swiper.但是我当时想到的却是,vue里边怎么用swiper?! 中国有句古话叫:天塌下来有个高的顶着. 在前端圈里,总有前仆后继的仁人志士相继挥洒着热汗(这里 ...

  3. 使用scrollpagination实现页面底端自动加载无需翻页功能

    当阅读到页面最底端的时候,会自动显示一个"加载中"的功能,并自动从服务器端无刷新的将内容下载到本地浏览器显示. 这样的自动加载功能是如何实现的?jQuery的插件 ScrollPa ...

  4. 适用于移动端、PC 端 Vue.js 图片预览插件

    1.安装:npm install --save vue-picture-preview 2.使用: (1)入口文件中main.js中全局引入: import Vue from 'vue' import ...

  5. js实现移动端手指左右上下滑动翻页效果

    var ele = document.getElementsByClassName("img-box")[0]; var beginX, beginY, endX, endY, s ...

  6. 【bootstrapV3】移动端和PC端的 滚动监听

    1.本代码适用于 bootstrap V3 的 页面滚动监听 2.效果: 3.代码: <!DOCTYPE html> <html lang="zh-CN"> ...

  7. 记录一下,PC端vue开发常用框架,已经用过elementUI和iview 接下来尝试另一个Muse-UI 喜欢它的点击效果

    官网地址: https://muse-ui.org/#/zh-CN/installation

  8. Atitit.pagging  翻页功能解决方案专题 与 目录大纲 v3 r44.docx

    Atitit.pagging  翻页功能解决方案专题 与 目录大纲 v3 r44.docx 1.1. 翻页的重要意义1 1.2. Dep废弃文档   paip.js翻页分页pageing组件.txt1 ...

  9. Atitit.列表页面and条件查询的实现最佳实践(2)------翻页 分页 控件的实现java .net php

    )------翻页 分页 控件的实现java .net php 1. 关于翻页有关的几大控件::搜索框控件,显示表格控件,翻页器,数据源控件.. 1 2. 翻页的显示格式:: 1 2.1. 通常ui- ...

随机推荐

  1. 记一次腾讯云MySQL数据库数据回滚

    如题,因为操作人员的问题,需要对数据库数据进行回滚. 可以看到,设置了7天自动备份,且是物理冷备. 什么是物理冷备?科普一下: (1)热备:在数据库运行时,直接进行备份,对运行的数据库没有影响.(2) ...

  2. 【helm & Tiller】报错Error: incompatible versions client[v2.14.1] server[v2.13.0] │

    helm是helm的客户端部分 tiller是helm的服务器端部分 报错 报错Error: incompatible versions client[v2.14.1] server[v2.13.0] ...

  3. node.js web应用优化之读写分离

    概述 先了解读写分离是什么,什么原理,解决了什么问题.什么是读写分离? 其实就是将数据库分为了主从库,一个主库用于写数据,多个从库完成读数据的操作,主从库之间通过某种机制进行数据的同步,是一种常见的数 ...

  4. 【ARTS】01_40_左耳听风-201900812~201900818

    ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...

  5. .net core 使用SignalR实现实时通信

    这几天在研究SignalR,网上大部分的例子都是聊天室,我的需求是把服务端的信息发送给前端展示.并且需要实现单个用户推送. 用户登录我用的是ClaimsIdentity,这里就不多解释,如果不是很了解 ...

  6. SQL命令如何分发到集群的各节点

    有些数据库集群的规模是很大的,有上百个节点,那么维护SQL命令如何快速分发给各个节点,例如:要加个字段,逐个节点操作那是十分低效,枯燥的. TreeSoft增加了[SQL分发]功能,简单配置,可以快速 ...

  7. 常见问题:MySQL/事务隔离

    数据库并行产生的问题 A事务撤销时,将B事务更改的数据撤销. A事务提交时,将B事务更改的同行数据覆盖. 脏读:A事务读取到了B事务未提交的数据. 不可重复读:A事务中同查询语句不幂等,读到已更新数据 ...

  8. Qt563x86vs2015.编译错误(TypeError: Property 'asciify' of object Core::Internal::UtilsJsExtension(0x????????) is not a function)

    1.在 编译或打开 pro时 有时会有这个错误 1.1.参考网址:Qt 编译错误 提示TypeError_ Property 'asciify' of object Core__Internal__U ...

  9. 微信小程序实战,与后台交互

    index.wxml <view class="container"> <text>{{txt}}</text> <input name= ...

  10. Net UI Spy工具:ManagedSpy

    Net UI Spy工具:ManagedSpy 很久之前在接手一个大型的Winform项目的时候.有如下困难: 1,项目很大整个产品的Build由1400多个Project组成 2,产品的组件.控件太 ...