Vue怎么实现分批加载数据
发表于:2024-10-25 作者:千家信息网编辑
千家信息网最后更新 2024年10月25日,本篇内容主要讲解"Vue怎么实现分批加载数据",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"Vue怎么实现分批加载数据"吧!分批加载数据最近在写vue的项目
千家信息网最后更新 2024年10月25日Vue怎么实现分批加载数据
本篇内容主要讲解"Vue怎么实现分批加载数据",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"Vue怎么实现分批加载数据"吧!
分批加载数据
最近在写vue的项目,因为后台返回的数据量太大,在调用了高德地图渲染"polygon"覆盖物的时候处理不过来,直接蹦掉了,然后后台小哥哥和我讲可以分批处理~没想到真的是快了很多很多,眼过千变不如手过一遍~,在此记录一下!!!
首先我们需要定义四个全局的变量
pagindex
页码pagesize
一页要请求多少条数据pagetotal
一共要请求多少次(总数 / pagesize),总是是后台返回的~intertimer
存的定时器的函数,方便清除定时器
export default { name: "map_app", inject:['reload'], data() { return { pagindex: 1, //页码 pagesize: 300, //页/条数 pagetotal: 0, //一共要请求的次数 intertimer: null, //定时器 } }}
然后再methods中写定时器 让定时器每隔三秒再去执行一个方法;
//定时器getPageInter(map) { this.loading = this.$loading({ //加载层 lock: true, text: "拼命加载中", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)" }); this.intertimer = setInterval(() => { this.intervalData(map); //每三秒调用一次方法 }, 3000); },
然后再这个方法里面我们去做判断,如果当前请求的页数超过一共要请求的次数就清楚定时器!
//定时器2intervalData(map) { if (this.pagindex > this.pagetotal) { clearInterval(this.intertimer); //关闭定时器 this.loading.close(); //关闭弹窗 this.pagindex = 1; } else { this.renderMesh(map); //数据渲染 this.pagindex += 1; }},
总数是后台小哥哥返回的,然后我们每次去请求接口的时候要给后台传当前是第几页,还有要请求多少条数据
renderMesh(map) { this.$axios .get(this.httpApi + "/api/Main/GetBlockMap", { params: { BlockCode: this.pageid, page: this.pagindex, //当前页码 rownum: this.pagesize //请求数量 } }) .then(res => { console.log(res); }) .catch(err => { console.log("请求失败233"); });}
因为我的总数是调用的另外一个接口,然后也写一下代码
this.$axios .get(this.httpApi + "/api/Main/GetBlockMapCount", { params: { BlockCode: this.pageid } }) .then(res => { let jsonData = eval("(" + res.data + ")"); //总数除每次请求多少条数据得出一共要请求多少次 this.pagetotal = Math.ceil(jsonData.totals / this.pagesize); }) .catch(err => { console.log("请求失败"); });
滚动加载数据
核心方法:
handleScroll: function () { var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; var windowHeitht = document.documentElement.clientHeight || document.body.clientHeight; var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight; if (scrollTop + windowHeitht >= scrollHeight - 2000) { if (this.scroll) { this.GetSpecialData(); } } }, GetSpecialData() { this.scroll = false; this.page.pageIndex++; this.load(this.page, this.query); },
监听:
mounted() { window.addEventListener("scroll", this.handleScroll); }, destroyed() { window.removeEventListener("scroll", this.handleScroll, false); },
到此,相信大家对"Vue怎么实现分批加载数据"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
数据
定时器
后台
方法
总数
页码
内容
哥哥
接口
时候
次数
处理
学习
实用
更深
清楚
没想到
代码
全局
兴趣
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
杭州国产服务器哪个好
数据库自动抓取技术研究
方舟服务器怎么改人物人数
遵义的软件开发有限公司
关于校园网络安全文章
泽思网络安全黑板报
数据库怎么根据时间查询总和
微信后台数据库
浦东新区智能化软件开发质量
LOL是不是服务器崩了
大话西游服务器架设
运行微信公众号需要服务器吗
检索文献可用的数据库
16岁学网络技术好吗
网络技术杭州公司
电力网络安全监管系统
怎样查询阿里云服务器
程序员软件开发怎么下载
如何找反向代理的服务器
教育行业网络安全文件
网络安全性为什么是无
终结者2手游武器数据库
excel服务器在公司应用
嘉定区质量网络技术供应
网络技术杭州公司
辅助驾驶软件开发
NFC写卡软件开发
软件开发公司的保密协议
基岩版一直卡在定位服务器
广西网络技术人员培训