分页

做分页时经常会遇到以下这样的需求,显示当前页的 开始条数 和 结尾条数

直接的写法:

可以换一种更好的表现方式:

用 三元运算符 计算 开始条数,

定义个方法 pageNum 计算 结尾条数

方法:

pageNum () {
      if (this.totalPage > this.pageIndex) {
        return (this.pageIndex * 10)
      } else if (this.totalPage < this.pageIndex) {
        return 0
      } else if (this.totalPage === this.pageIndex) {
        return this.total
      } else {
        return this.total - this.pageIndex * 10
      }
    }
原文地址:https://www.cnblogs.com/listen9436/p/10671376.html