vue项目 h5上拉加载(分页功能)
2024-09-08 14:02:58
<template>
<div class="receivable">
<div class="application-header flex-betweenCenter" @click="goBack">
<img
class="prod-header-navImg"
src="../../assets/images/icon_back.png"
alt=""
/>
<div class="font18 hy_color weightBold">登录日志</div>
<div></div>
</div>
<div class="receivable-main">
<ul class="scroll-box" :style="{ height: clientHeight + 'px' }" v-if="is_number==1" @scroll="handleScroll($event)">
<li class="log-ul-li" v-for="item in list" :key="item.id">
<div>
<div>{{ item.type }}</div>
<div class="log-color">{{ item.create_time }}</div>
</div>
<div>{{ item.operate }}</div>
</li>
<div class="bottom-tishi">{{loadingText}}</div>
</ul>
<div v-if="is_number == 2">
<div class="emptaype-box">
<img src="../../assets/images/empty_order.png" alt="" />
<p>暂无数据哦!~</p>
</div>
</div>
</div>
<div class="receivable-footer"></div>
</div>
</template>
<script>
import { storage } from "@/utils/storage";
export default {
name: "Receivable",
data() {
return {
is_number: 1,
p: 1,
list: [],
timer: null,
loadingText:'',
clientHeight: null
};
},
created() {this._getUserLoginLog();
this.clientHeight = +document.documentElement.clientHeight -60
},
methods: {
goBack() {
this.$router.go(-1);
},
_getUserLoginLog() {
let data = {
token: this.token,
p: 1,
};
this.$api.getUserLoginLog(data).then((res) => {
if (res.data.length > 0) {
this.list = res.data;
this.is_number = 1;
this.p++
} else {
this.is_number = 2;
}
});
},
handleScroll(e) {
//这里使用个延时加载,不然滑动屏幕的时候会不断触发方法,去计算高度,浪费性能
let that = this
clearTimeout(this.timer)
that.timer = setTimeout(function () {
let clientHeight = e.target.clientHeight;
let scrollTop = e.target.scrollTop;
let scrollHeight = e.target.scrollHeight;
console.log(clientHeight,scrollTop,scrollHeight)
if (clientHeight + scrollTop >= scrollHeight - 10) {
that.getUserLoginLogMeuns()
}
}, 500);
},
getUserLoginLogMeuns() {
this.loadingText = '加载更多'
let data = {
token: this.token,
p: this.p,
};
this.loadingText = '加载中...'
this.$api.getUserLoginLog(data).then((res) => {
if (res.data.length > 0) {
this.list = this.list.concat(res.data)
this.is_number = 1
} else if(res.data.length==0){
this.loadingText = '没有更多了'
}
this.p++
});
},
},
};
</script>
最新文章
- VMware的三种网络连接方式区别
- Learning Roadmap of Deep Reinforcement Learning
- 【原创】开发Kafka通用数据平台中间件
- hadoop拾遗(二)---- 文件模式
- ArcGIS Engine Style文件操作
- AndroidStudio字体主题样式分享
- Android短信拦截和电话拦截
- opencv在arm和x86在移植
- MessageBoxButtons.OKCancel的选择事件
- angular $compiler
- python用户管理系统
- 【webpack系列】从零搭建 webpack4+react 脚手架(一)
- c++的虚继承
- 【机器学习】主成分分析法 PCA (II)
- lombok的使用和原理
- 检测三种不同操作系统的Bash脚本
- 命令行 设置redis 时间
- App爬虫神器mitmproxy和mitmdump的使用
- [Machine Learning &; Algorithm] 随机森林(Random Forest)-转载
- 线性判别分析LDA详解
热门文章
- 《Go 精进之路》 读书笔记 (第一次更新)
- 中国数字化是怎么转型成新范式TOP 50的?
- HDU2196 Computer (树形DP-换根)
- 备份 MySQL 的 shell 脚本(mysqldump版本) shell脚本
- c语言KMP匹配算法与字符串替换算法
- Docker之介绍与安装
- 部署redis-cluster
- 【Bluetooth|蓝牙开发】二、蓝牙开发入门
- 华为开发者大会HDC2022:HMS Core 持续创新,与开发者共创美好数智生活
- Codeforces Global Round 23 D.Paths on the Tree(记忆化搜索)