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 分页加载,向上滑动,依次加载数据。的更多相关文章

  1. iScroll.js 向上滑动异步加载数据回弹问题

    iScroll是一款用于移动设备web开发的一款插件.像缩放.下拉刷新.滑动切换等移动应用上常见的一些效果都可以轻松实现. 现在最新版本是5.X,官网这里:http://iscrolljs.com/ ...

  2. FMX StringGrid向上滑动自动加载记录(二)

    写完FMX StringGrid向上滑动自动加载记录(一)自己也觉得不理想,实现的别扭与复杂,现在找到更好的实现方法,原来,StringGrid从基类TCustomPresentedScrollBox ...

  3. 加载信息,先从数据库取出5条实现分页,鼠标向上滑动触发Ajax再加载5条,达到异步刷新,优化加载。。。

    php数据库取数据 <?php include("conn1.php"); include('../function/functions.php'); $page=intva ...

  4. vue.js组件之间的通讯-----父亲向儿子传递数据,儿子接收父亲的数据

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. FMX StringGrid向上滑动自动加载记录(一)

    有时候,做的app还是需要用StringGrid来显示数据,但如果用StringGrid的Livebinding绑定到一个数据集TDataset,当记录超过1000条时,效率非常低,甚至达不到实用状态 ...

  6. Web App 向上滑动动态加载数据 2015-06-11 09:36 20人阅读 评论(0) 收藏

    好久没有写博客了 - - ,个人原因 个人原因..  宣传一下...自己的.NET群:252713569 欢迎各位大神加入 嗯..最近在公司开发微信平台的东西..需要做一个WebAPP(PS:其实就是 ...

  7. 【Vue.js】代码优化:在dom中加一行v-if就可少写一个循环类方法

    [问题描述] 把当前用户的购物车中(cartList),商品(good)选中字段checked = true的商品在订单页面中进行展示出来. [一般做法](两次循环) 首先取出当前用户的购物车列表,循 ...

  8. vue.js 分页

    <template> <div class="index"> <el-pagination background :hide-on-single-pa ...

  9. html+vue.js 实现分页可兼容IE

    当功能比较简单,在单一html中使用vue.js分页展示数据,并未安装脚手架,或使用相关UI框架,此时需要手写一个分页器,不失为最合理最便捷的解决方案, 先看一下实现效果: 上代码: 1.简单搞一搞 ...

随机推荐

  1. C++入门经典-例2.9-输出十六进制数以及大写的十六进制数

    1:代码如下: #include "stdafx.h" #include <iostream> #include <iomanip> using names ...

  2. LeetCode 96. 不同的二叉搜索树(Unique Binary Search Trees )

    题目描述 给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种? 示例: 输入: 输出: 解释: 给定 n = , 一共有 种不同结构的二叉搜索树: \ / / / \ \ / / ...

  3. LeetCode 55. 跳跃游戏(Jump Game)

    题目描述 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] 输出: ...

  4. cucumber+selenium

    工程结构 pom <?xml version="1.0" encoding="UTF-8"?> <project xmlns="ht ...

  5. 关于函数中参数kwarg.setdefault()的用法

    1.kwarg.setdefault() setdefault()是给字典传递一个默认值    当给字典传递数据时 setdefault()是字典默认的一个参数,当有新的数据时,就会使用新的数据

  6. gcc编译器创建和使用静态库、动态库

    http://www.cnblogs.com/dyllove98/archive/2013/06/25/3155599.html 目录树结构: test/include/hello.h #ifdef ...

  7. Professional JavaScript for Web Developers P224-P225

    然后第二段代码执行过程中,有1个global variabe object,1个createFunction activation object,10个anonymous function1 acti ...

  8. Keytool生成证书

    一.生成证书keytool -genkey -alias 别名 -keyalg RSA -keysize 1024(密钥位数) -keypass 密码 -validity 365(默认90天) -ke ...

  9. lua基础学习(一)

    设计目的: 为了嵌入应用程序中,从而为应用程序提供灵活的扩展和定制功能.   特性: 1.编译之后仅仅100k,可以很方便嵌入别的程序里. 2.可扩张性,Lua提供了非常易于使用的扩展接口和机制:由宿 ...

  10. python 并发编程 多线程 信号量

    一 信号量 信号量也是一把锁,可以指定信号量为5,对比互斥锁同一时间只能有一个任务抢到锁去执行,信号量同一时间可以有5个任务拿到锁去执行 如果说互斥锁是合租房屋的人去抢一个厕所,那么信号量就相当于一群 ...