纯前端简单实现表格分页

本文介绍了如何在Vue应用中设置page和size字段进行分页,使用el-pagination组件配置分页功能,以及如何在el-table中添加操作列以实现列表数据的删除。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.设置两个字段page,size,来存储当前点击的页,和每页的行数,然后在表格数据这里设置,:data=“列表数据.slice((page - 1) *size, page *page_size)”

2.el-pagination分页器中配置一下

@current-change=“answerPageChange” 当前页码(函数)主要是确定点击的是第几页,然后改变page的
:current-page.sync=“page” 页码
:page-size=“size” 每页显示多少个
layout=“prev, pager, next, jumper” 需要的功能,具体可以看官网
:total=“orderManagementContent.length” 总条数,必须要有,不然不能分页

 <el-table :data="comment_content.slice((goods_page_config.page - 1) *goods_page_config.page_size, goods_page_config.page * goods_page_config.page_size)" style="width: 100%; flex: 1" size="medium" border
 :header-cell-style="{ fontWeight: 'normal', color: '#666', background: '#F6F6F6', fontSize: '16px', height: '60px' }"
:cell-style="{ fontSize: '12px', color: '#333', height: '70px', }">
 </el-table>
<div class="pagination">
	<el-pagination
      @current-change="answerPageChange"
      :current-page.sync="answer_page_config.page"
      :page-size="answer_page_config.page_size"
      layout="prev, pager, next, jumper"
      :total="comment_content.length">
    </el-pagination>
</div>
//设置的数据
comment_content:[],
answer_page_config: {
        page: 1,
        page_size: 5,
      },
  answerPageChange(val) {
  //val  当前页码
      this.answer_page_config.page = val;
    },

3.删除列表中的行

<el-table-column label="操作" align="center" width="220px">
	<template slot-scope="scope">
		<div class="link-list">
			<el-link type="danger" :underline="false" @click="deleteGoods(scope.row)">删除</el-link>
		</div>
	</template>
</el-table-column>
 deleteGoods(rows) {
   this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }) .then(() => {
	//order_no  一个唯一标识符		
	this.comment_content=this.comment_content.filter(item=>item.order_no!=rows.order_no)
	this.$message({
         type: "success",
         message: "删除成功!",
         });
	}).catch(() => {
        this.$message({
         	type: "info",
         	 message: "已取消删除",
         	 });
        });
},
package com; public class Pager { private int totalRows = 0; // 记录总数 private int totalPages = 0; // 总页数 private int pageSize = 10; // 每页显示数据条数,默认为10条记录 private int currentPage = 1; // 当前页数 private boolean hasPrevious = false; // 是否有上一页 private boolean hasNext = false; // 是否有下一页 public int getSearchFrom() { return (currentPage - 1) * pageSize; } public Pager() { } public void init(int totalRows) { this.totalRows = totalRows; this.totalPages = ((totalRows + pageSize) - 1) / pageSize; refresh(); // 刷新当前页面信息 } /** * * @return Returns the currentPage. * */ public int getCurrentPage() { return currentPage; } /** * * @param currentPage * current page * */ public void setCurrentPage(int currentPage) { this.currentPage = currentPage; refresh(); } /** * * @return Returns the pageSize. * */ public int getPageSize() { return pageSize; } /** * * @param pageSize * The pageSize to set. * */ public void setPageSize(int pageSize) { this.pageSize = pageSize; refresh(); } /** * * @return Returns the totalPages. * */ public int getTotalPages() { return totalPages; } /** * * @param totalPages * The totalPages to set. * */ public void setTotalPages(int totalPages) { this.totalPages = totalPages; refresh(); } /** * * @return Returns the totalRows. * */ public int getTotalRows() { return totalRows; } /** * * @param totalRows * The totalRows to set. * */ public void setTotalRows(int totalRows) { this.totalRows = totalRows; refresh(); } // 跳到第一页 public void first() { currentPage = 1; this.setHasPrevious(false); refresh(); } // 取得上一页(重新设定当前页面即可) public void previous() { if (currentPage > 1) { currentPage--; } refresh(); } // 取得下一页 public void next() { //System.out.println("next: totalPages: "
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值