项目中数据量大,分页查询慢的解决方案

项目中分页查询时间过长

项目中可能会遇到数据量很大,同时有需要多表联合查询的时候,这个时候,在计算页码的时候,就会遇到如何处理的问题。

在项目中我的处理方案

  1. mysql数据库索引优化(一般情况下可以满足需求)
  2. 前端获取数据时,不计算总数
    前端页码布局
    <div>
        <div style="float: right; margin: 20px;">
            <span><el-button size="small" :disabled="flag" @click="toBeferPage">上一页</el-button></span>
            <span style="margin: 0 10px;"><el-button size="small" @click="toAfterPage">下一页</el-button></span>
            <span>前往<el-input size="small" @blur="toPageBlur" v-model.number="ruleForm.pageIndex" style="width: 80px; margin: 0 10px;" ></el-input></span>
         </div>
     </div>
    
    前端样式
    在这里插入图片描述
    js代码
    // 页码跳转
    toPageBlur() {
      const that = this;
      if (that.ruleForm.pageIndex < 1) {
        that.$message.warning("请输入大于0的数字");
        that.ruleForm.pageIndex = 1;
        that.flag = true;
        return false;
      }
      if (that.ruleForm.pageIndex < 2) {
        that.flag = true;
      } else {
        that.flag = false;
      }
      //  获取分页数据信息函数
      that.getList();
    },
    // 上一页
    toBeferPage() {
      const that = this;
      that.ruleForm.pageIndex = that.ruleForm.pageIndex - 1;
      if (that.ruleForm.pageIndex < 2) {
        that.flag = true;
      }
      //  获取分页数据信息函数
      that.getList();
    },
    // 下一页
    toAfterPage() {
      const that = this;
      that.ruleForm.pageIndex = that.ruleForm.pageIndex + 1;
      that.flag = false;
      //  获取分页数据信息函数
      that.getList();
    },
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值