分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

纯JS实现加载更多(VUE框架)

发布时间:2023-09-06 01:24责任编辑:沈小雨关键词:暂无标签
<template> ???<div class = ‘car_list‘ reft=‘scrollobx‘ @scroll=‘scrollready($event)‘> ???</div></template><script> ???export default { ???????data() { ???????????return ?{ ???????????????lengthThreshold: 50, //当滑动到距离低端50px时,更新数据 ???????????????timeThreshold: 300, ????????????????promise: null ???????????} ???????}, ???????methods: { ???????????// 滚动加载列表 ???????????scrollready() { ???????????????if(this.shouldScroll()) { ???????????????????if (this.promise) { ???????????????????????return; ???????????????????} ???????????????????// 进行加载 ???????????????????this.fn(); ???????????????????// 防止多次滑动,频繁请求后台资源 ???????????????????let self = this; ???????????????????this.promise = setTimeout(() => { ???????????????????????self.promise = null; ???????????????????}, this.timeThreshold); ???????????????} ???????????}, ???????????// 调用父组件请求资源服务 ???????????fn() { ???????????????this.$emit(‘scrollChange‘); ???????????}, ???????????shouldScroll() { ???????????????if(document.scrollTop === 0) {// 滑动距离为0,还没开始滑动 ???????????????????return false; ???????????????}
???????????????// 列表高度 - 列表可视高度 - 滑动的高度 < 50px , 则加载更多 ???????????????return this.$refs.scrollbox.scrollHeight - this.$refs.scrollbox.clientHeight - this.$refs.scrollbox.scrollTop < this.lengthThreshold; ???????????}, ???????} ???}</script> ???

父组件的请求服务方法:

queryCarApplyShareList() { ???????this.Load = true; ???????CarResources.methods.queryCarApplyShareList(this.http, this.pageNo, this.pageSize).then((res) => { ?????????if (res && res.status === 200) { ??????????????if (this.pageNo === 1) { // 加载第一页数据 ??????????????????this.CarList = res.data || []; ??????????????} else { // 加载更多 ?????????????????this.CarList = this.CarList.concat(res.data); ??????????????} ??????????????this.IsLastPage = res.data.length === 0 ?????????} ?????????this.Load = false; ??????}, () => { ?????????this.Load = false; ?????????console.log(‘接口报错‘); ??????});},

  

纯JS实现加载更多(VUE框架)

原文地址:http://www.cnblogs.com/pengshengguang/p/7815589.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved