当前位置: 首页 > news >正文

el-table + el-pagination 前端实现分页操作

el-table + el-pagination 前端实现分页操作

后端返回全部列表数据,前端进行分页操作

html代码
<div>
  <el-table :data="tableData" border>
    <el-table-column label="序号" type="index" width="50" />
    <el-table-column prop="name" label="礼品名称">
      <template slot-scope="scope">
        {{ scope.row.orderInfo.itemName }}
      </template>
    </el-table-column>
    <el-table-column prop="orderNum" label="订单编号" width="120">
      <template slot-scope="scope">
        {{ scope.row.orderInfo.orderNum }}
      </template>
    </el-table-column>
    <el-table-column prop="name" label="物流编号" width="130">
      <template slot-scope="scope">
        {{ scope.row.orderInfo.expressCode }}
      </template>
    </el-table-column>
    <el-table-column prop="name" label="礼品单价" width="80">
      <template slot-scope="scope">
        {{ scope.row.orderInfo.unitPrice }}
      </template>
    </el-table-column>
    <el-table-column prop="name" label="礼品数量" width="80">
      <template slot-scope="scope">
        {{ scope.row.orderInfo.quantity }}
      </template>
    </el-table-column>
    <el-table-column prop="name" label="订单金额" width="80">
      <template slot-scope="scope">
        {{ scope.row.orderInfo.price }}
      </template>
    </el-table-column>
    <el-table-column prop="name" label="订单日期" width="130">
      <template slot-scope="scope">
        {{ scope.row.orderInfo.orderDate }}
      </template>
    </el-table-column>
    <el-table-column prop="isError" label="是否成功" width="80">
      <template slot-scope="scope">
        {{ scope.row.isError ? '否' : '是' }}
      </template>
    </el-table-column>
    <el-table-column prop="errorInfo" label="错误信息">
      <template slot-scope="scope">
        {{ scope.row.errorInfo }}
      </template>
    </el-table-column>
  </el-table>

  <el-pagination
    :total="total"
    :current-page="page"
    :page-size="size"
    :page-sizes="pageSizes"
    layout="total, sizes, prev, pager, next, jumper"
    @size-change="sizeChange"
    @current-change="currentChange"
  />
</div>
js代码

两种方式:
① slice
② splice

<script>
export default {
  name: 'ImportLog',
  data() {
    return {
      page: 1, // 第几页
      size: 20, // 一页多少条
      total: 0, // 总条目数
      pageSizes: [20, 40, 60, 80, 100, 120, 140, 160, 180, 200], // 可选择的一页多少条
      tableData: [], // 表格绑定的数据
      allData: [], // 全部数据
    }
  },
  created() {
    this.getTabelData2()
  },
  methods: {
    // 获取表格数据,自行分页(slice)
    getTabelData() {
      // allData为全部数据
      this.tableData = this.allData.slice(
        (this.page - 1) * this.size,
        this.page * this.size
      )
      this.total = this.allData.length
    },
    // 获取表格数据,自行分页(splice)
    getTabelData2() {
      const data = JSON.parse(JSON.stringify(this.allData))
      this.tableData = data.splice(
        (this.page - 1) * this.size,
        this.size
      )
      this.total = this.allData.length
    },
    // page改变时的回调函数,参数为当前页码
    currentChange(val) {
      this.page = val
      this.getTabelData2()
    },
    // size改变时回调的函数,参数为当前的size
    sizeChange(val) {
      this.size = val
      this.page = 1
      this.getTabelData2()
    }
  }
}
</script>

相关文章:

  • secp256k1的模数P是如何选择的?
  • Java反射机制详解:原理、应用与最佳实践
  • Python内存管理探秘:让程序轻盈如羽的底层艺术
  • 畅享Mac桌面版TikTok!
  • 70. Linux驱动开发与裸机开发区别,字符设备驱动开发
  • 服务器中防火墙的重要性
  • 上门家政小程序实战,从0到1解决方案
  • 学习本地部署DeepSeek的过程(基于LM Studio)
  • 调用通义千问实现语音合成并将合成的音频通过扬声器播放
  • Transformer 通关秘籍2:利用 BERT 将文本 token 化
  • 【悲观锁和乐观锁有什么区别】以及在Spring Boot、MybatisPlus、PostgreSql中使用
  • 简历含金量的描述和注意事项!
  • 如何用Redis统计网站的UV
  • 影刀魔法指令3.0:开启自动化新篇章
  • 计算机视觉3——模板匹配与拟合
  • Maven入门
  • 3.26学习总结
  • Android系统的安全问题 - Android的Trusty TEE
  • LLM实践(二)——基于llama-factory的模型微调
  • OpenGL绘制文本
  • 俄外长:俄将在不损害伙伴关系前提下发展对美关系
  • 15世纪以来中国文化如何向欧洲传播?《东学西传文献集成初编》发布
  • 劳动最光荣!2426人受到表彰
  • 我国首个核电工业操作系统发布,将在华龙一号新机组全面应用
  • 中央纪委办公厅公开通报3起整治形式主义为基层减负典型问题
  • 传染病防治法修订草案提请三审,拟加强医疗机构疾控能力建设