vue+element的table列表删除当前页的数据显示前一页

小编最近在一直在做关于表格页面,因为做得多了熟悉里面的套路了,O(∩_∩)O哈哈~,但是由于感觉自己很熟悉了,自测的时候还是忽略了一个很重要的问题o(╥﹏╥)o,被测试给揪出来了,但是也不是什么大问题三下五除二我就搞定啦,但是鉴于它有多种可能性,还是记录一下吧。

第一种
在这里插入图片描述
这种方法是最常见也是最简单的只需要在删除成功的回调里面写一下的方法就可以了

if (this.total % this.pageSize === 1) {    // 表格总数量 % 行数  余出的就是当前页有几个
   const lastPage = (this.total + this.pageSize - 1) / this.pageSize  // (表格总数量 +行数 -1) / 行数
   if (this.currentPage === lastPage) { // 当前页 === (表格总数量 +行数 -1) / 行数
     this.currentPage = this.currentPage - 1 // 减去一页就是前一页
   }
}

第二种

一个是点击全部的,一个点击是单选的
在这两个事件中分别触发不一样的判断

// 在点击全部复选框时
if (this.currentPage !== 1) {
  this.currentPage = this.currentPage - 1
}
// 点击单选复选框时
if (this.total % this.pageSize === 1) {
  const lastPage = (this.total + this.pageSize - 1) / this.pageSize
  if (this.currentPage === lastPage) {
    this.currentPage = this.currentPage - 1
  }
}

第三种

在这里插入图片描述
这种其实跟第二种相似但是又很不相似
他还多了一种选择多个在移除

// this.fundCodeSelectList 这个变量是个数组,里面放的是要移除的代码code
if (this.currentPage !== 1 && this.fundCodeSelectList.length == 1) { // 如果单选 执行
  if (this.total % this.pageSize === 1) {
    const lastPage = (this.total + this.pageSize - 1) / this.pageSize
    if (this.currentPage === lastPage) {
      this.currentPage = this.currentPage - 1
    }
  }
} else if (this.fundCodeSelectList.length > 1 && this.fundCodeSelectList.length < this.pageSize && this.fundCodeSelectList.length !== this.total % this.pageSize) {
  this.fundCodeSelectList = []
  this.getGetFundFollowList()
} else { // 如果多选 执行
  if (this.currentPage !== 1) {
    this.currentPage = this.currentPage - 1
  }
}

最后一种方法还需要在优化一下,等我闲暇时在更新

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值