vue.js 分页加载,向上滑动,依次加载数据。
export default {
layout: 'default',
data(){
return{
page:1,
pageSize:10,
orderListArr:[],
prodListLoadingOver:false,
prodListLastPage: false,
}
},
mounted(){
window.addEventListener('scroll', this.handleScroll);
},
created(){
this.fetchOrderListAction();
},
methods:{
fetchOrderListAction(){
let reqBody = {};
reqBody.page = this.page;
reqBody.pageSize = this.pageSize;
this.prodListLoadingOver = false;
fetchOrderList(JSON.stringify(reqBody)).then((res) => {
let resData = res.data;
if (resData.respHeader && resData.respHeader.resultCode === 0) {
this.prodListLoadingOver = true;
this.orderListArr = resData.respBody.subsList;
if(this.page == 1){
this.orderListArr = resData.respBody.subsList;
}else{
this.orderListArr = this.orderListArr.concat(resData.respBody.subsList);
}
if(resData.respBody.subsList.length < this.pageSize){
this.prodListLastPage = true;
}
}else{
Toast({
message: resData.respHeader.message || "网络异常",
});
}
});
},
handleScroll(){
let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
let h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; //屏幕的高度
let prodListHeight = document.querySelector('.myOrderListWrapper').offsetHeight-h-20; //.myOrderListWrapper 商品列表容器
console.log(scrollTop,":::",prodListHeight)
if(scrollTop > prodListHeight && this.prodListLoadingOver && !this.prodListLastPage){
this.page = this.page + 1;
this.fetchOrderListAction();
}
},
},
destroyed(){
window.removeEventListener('scroll', this.handleScroll);
}
}
在mounted中注册滚动事件,在destroyed中销毁。。。其他鼠标事件也是如此。
vue.js 分页加载,向上滑动,依次加载数据。的更多相关文章
- iScroll.js 向上滑动异步加载数据回弹问题
iScroll是一款用于移动设备web开发的一款插件.像缩放.下拉刷新.滑动切换等移动应用上常见的一些效果都可以轻松实现. 现在最新版本是5.X,官网这里:http://iscrolljs.com/ ...
- FMX StringGrid向上滑动自动加载记录(二)
写完FMX StringGrid向上滑动自动加载记录(一)自己也觉得不理想,实现的别扭与复杂,现在找到更好的实现方法,原来,StringGrid从基类TCustomPresentedScrollBox ...
- 加载信息,先从数据库取出5条实现分页,鼠标向上滑动触发Ajax再加载5条,达到异步刷新,优化加载。。。
php数据库取数据 <?php include("conn1.php"); include('../function/functions.php'); $page=intva ...
- vue.js组件之间的通讯-----父亲向儿子传递数据,儿子接收父亲的数据
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- FMX StringGrid向上滑动自动加载记录(一)
有时候,做的app还是需要用StringGrid来显示数据,但如果用StringGrid的Livebinding绑定到一个数据集TDataset,当记录超过1000条时,效率非常低,甚至达不到实用状态 ...
- Web App 向上滑动动态加载数据 2015-06-11 09:36 20人阅读 评论(0) 收藏
好久没有写博客了 - - ,个人原因 个人原因.. 宣传一下...自己的.NET群:252713569 欢迎各位大神加入 嗯..最近在公司开发微信平台的东西..需要做一个WebAPP(PS:其实就是 ...
- 【Vue.js】代码优化:在dom中加一行v-if就可少写一个循环类方法
[问题描述] 把当前用户的购物车中(cartList),商品(good)选中字段checked = true的商品在订单页面中进行展示出来. [一般做法](两次循环) 首先取出当前用户的购物车列表,循 ...
- vue.js 分页
<template> <div class="index"> <el-pagination background :hide-on-single-pa ...
- html+vue.js 实现分页可兼容IE
当功能比较简单,在单一html中使用vue.js分页展示数据,并未安装脚手架,或使用相关UI框架,此时需要手写一个分页器,不失为最合理最便捷的解决方案, 先看一下实现效果: 上代码: 1.简单搞一搞 ...
随机推荐
- 错误“Object reference not set to an instance of an object”的解决方法
在进行unity游戏制作的C#代码编写时,会遇到“NullReferenceException: Object reference not set to an instance of an objec ...
- NMS(非极大值抑制算法)
目的:为了消除多余的框,找到最佳的物体检测的位置 思想: 选取那些领域里分数最高的窗口,同时抑制那些分数低的窗口 Soft-NMS
- python MySQLdb 一个连接connection多个cursor
使用MySQLdb时,如果创建一个连接connection,多个线程同时使用,会不会有问题? 在下文中,我们将模拟这种场景,看是否会出现问题. 1.示例 1.1 正常的情况 创建一个连接,两个线程同时 ...
- leetcode 328 奇偶链表
更新代码: 开头检测是否需要调整(是否具有第三个节点) 使用三个ListNode* 变量记录奇偶链表的头尾headA,tailA为奇链表,headB为偶数链表,由于只需要最后令tailA->ne ...
- 详解git pull和git fetch的区别
前言 在我们使用git的时候用的更新代码是git fetch,git pull这两条指令.但是有没有小伙伴去思考过这两者的区别呢?有经验的人总是说最好用git fetch+git merge,不建议用 ...
- mingw gcc 静态 static 编译 dav1d libdav1d.a
export CC=/mingw/bin/gcc export CXX=/mingw/bin/g++ meson --prefix "/usr/local" build --bui ...
- centos中切换图形与命令行界面
1.在命令行的centos中安装图形化 配置本地源 [root@localhost yum.repos.d]# yum clean all [root@localhost yum.repos.d]# ...
- P1706 【全排列问题】
超级无敌大题面~~ 这题倒也花了我不少时间,不停想节省空间,但这也确实是最省的了... 主要思路呢,要注意标记数有没有选过,并标记每个数的输出顺序.. 具体注释见代码: #include<cst ...
- Linux 命令 watch 监测命令的运行结果
watch 命令周期性地执行命令,全屏显示输出命令.watch命令可以监测一个命令的运行结果 命令参数 -n, --interval 设置间隔时间.默认情况下,watch 每隔 2 秒执行一次命令. ...
- HDU 1171 Big Event in HDU (动态规划、01背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...