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.简单搞一搞 ...
随机推荐
- windows spark1.6
jdk1.7 scala 2.10.5 spark 1.6.1 http://spark.apache.org/downloads.html hadoop 2.6.4 只需要留bin https:// ...
- JSP——JSTL定制标签 - 递归标签显示属性结构
编写定制标签分为三个步骤:编写标签处理器.配置标签.使用标签. 1.标签处理器 标签处理器和标签是一一对应的关系 package com.oolong.utils.customtags; impo ...
- Centos6 源码安装mysql5.6
这里介绍如何使用centos6.*来安装mysql5.6版本. 先做一下准备工作 确定好用于运行mysql的用户,安全起见,建议拒绝次用户登录,仅用于运行程序. useradd mysql -s/sb ...
- 【转】c语言动态与静态分配
https://blog.csdn.net/qq_43519310/article/details/85274836 https://blog.csdn.net/qq_38906523/article ...
- mysql--创建表,插入数据,修改表名,删除表,简单查询/内连接、左/右连接
创建表mm: 其中id为主键且自增长 ) primary key not null unique auto_increment, name ) not null, age ), class ) no ...
- JS获取表单元素的value
<!-- 1.option selected属性,如果我们在下拉列表里面选择了一个option那么他的selected="true" ,如果我们想设置当前的option是选中 ...
- angularjs的部分总结
就在这个星期,我们学习了一个神奇的框架叫:"Angular js",它的神奇之处不是它的功能有多强,甚至它的功能还是很简陋的,但是它的那种思想是非常牛逼的;他完全抛弃了我们现在所常 ...
- WebApi使用二进制方式上传和下载文件
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; usi ...
- When specified, "proxy" in package.json must be a string.
react项目在package.json中配置proxy之后,报错 $ npm run start > img@ start D:\xx\src\img > react-scripts s ...
- HDU 2100 Lovekey (26进制大数、字符串)
Lovekey Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...