pc端vue 滚动到底部翻页
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
}
},
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 滚动到底部翻页的更多相关文章
- 基于vue实现上下滑动翻页效果
18年年底的时候,一直在做年度报告的H5页面,因为项目需要,需要实现上下滑动翻页,并且上滑的页面比正常页面的比例要缩小一定比例. 效果类似于http://www.17sucai.com/pins/de ...
- 转载 vue-awesome-swiper - 基于vue实现h5滑动翻页效果
说到h5的翻页,很定第一时间想到的是swiper.但是我当时想到的却是,vue里边怎么用swiper?! 中国有句古话叫:天塌下来有个高的顶着. 在前端圈里,总有前仆后继的仁人志士相继挥洒着热汗(这里 ...
- 使用scrollpagination实现页面底端自动加载无需翻页功能
当阅读到页面最底端的时候,会自动显示一个"加载中"的功能,并自动从服务器端无刷新的将内容下载到本地浏览器显示. 这样的自动加载功能是如何实现的?jQuery的插件 ScrollPa ...
- 适用于移动端、PC 端 Vue.js 图片预览插件
1.安装:npm install --save vue-picture-preview 2.使用: (1)入口文件中main.js中全局引入: import Vue from 'vue' import ...
- js实现移动端手指左右上下滑动翻页效果
var ele = document.getElementsByClassName("img-box")[0]; var beginX, beginY, endX, endY, s ...
- 【bootstrapV3】移动端和PC端的 滚动监听
1.本代码适用于 bootstrap V3 的 页面滚动监听 2.效果: 3.代码: <!DOCTYPE html> <html lang="zh-CN"> ...
- 记录一下,PC端vue开发常用框架,已经用过elementUI和iview 接下来尝试另一个Muse-UI 喜欢它的点击效果
官网地址: https://muse-ui.org/#/zh-CN/installation
- Atitit.pagging 翻页功能解决方案专题 与 目录大纲 v3 r44.docx
Atitit.pagging 翻页功能解决方案专题 与 目录大纲 v3 r44.docx 1.1. 翻页的重要意义1 1.2. Dep废弃文档 paip.js翻页分页pageing组件.txt1 ...
- Atitit.列表页面and条件查询的实现最佳实践(2)------翻页 分页 控件的实现java .net php
)------翻页 分页 控件的实现java .net php 1. 关于翻页有关的几大控件::搜索框控件,显示表格控件,翻页器,数据源控件.. 1 2. 翻页的显示格式:: 1 2.1. 通常ui- ...
随机推荐
- 【插件式框架探索系列】应用程序域(AppDomain)
应用程序域(AppDomain)已经不是一个新名词了,只要熟悉.net的都知道它的存在,不过我们还是先一起来重新认识下应用程序域吧,究竟它是何方神圣. 应用程序域 众所周知,进程是代码执行和资源分配的 ...
- ES6深入浅出-4 迭代器与生成器-5.科班 V.S. 培训
为什么要学用不到的东西 科班是把你未来一二十年用的东西都给你入个门 做前端 三年后一定要再学一门语言. 买一本图解算法 培训讲究的是技能,只能满足3到5年,而不是术,学术学的是你未来10年甚至20年用 ...
- ES6深入浅出-4 迭代器与生成器-1.字面量增强
今天的内容 字面量literal 写出来就是它的值 例如字符串hello.这就是自变量. 一个空对象,也是自变量 写出来就是代表它写出来的那个意思就是自变量. 与其相反的就是构造出来的.例如下面的ne ...
- Qt编写气体安全管理系统11-数据打印
一.前言 在各种软件系统中,数据打印也是常用的功能之一,一般来说会对查询的数据结果导出到excel,还会对查询的数据结果直接打印,在Qt中提供了打印机类QPrinter,在printsupport组件 ...
- pytorch中调整学习率的lr_scheduler机制
有的时候需要我们通过一定机制来调整学习率,这个时候可以借助于torch.optim.lr_scheduler类来进行调整:一般地有下面两种调整策略:(通过两个例子来展示一下) 两种机制:LambdaL ...
- Jackson解析自定义json到实体类
json文本 { "status": 0, "result": { "final": true, "hypotheses" ...
- 【pip升级导致错误】 多个pip导致明明已经安装了包但是报no module错误
原来一直用apt install 默认安装的pip 8.01版本,今天因为一些原因,将pip升级到了19.01.升级后就导致了错误. 直接pip installl --upgrade pip,发现报权 ...
- 【KMP】POJ 2185 Milking Grid -- Next函数的应用
题目链接:http://poj.org/problem?id=2185 题目大意:求一个二维的字符串矩阵的最小覆盖子矩阵,即这个最小覆盖子矩阵在二维空间上不断翻倍后能覆盖原始矩阵. 题目分析:next ...
- echarts移动端demo
说明:建议移动端使用的时候自己定制需要的东西,详情看官网 ECharts 效果图: 代码: <!DOCTYPE html> <html style="height: 1 ...
- 前端研究CSS之内联元素块级化/区域大小/文字和图标的位置
做了一天的小按钮基本都是文字+小图标的组合,问题挺多处理的不好,现在总结一下做个了断. //页面结构 <span class="b"> <a href=" ...