WEB端分页显示实例

1、页面html文件
<div>
  <el-table :data="tableData" style="width:100%" border>
    <el-table-column type="index" width="50"></el-table-column>
    <el-table-column prop="name" width="180" label="sid"></el-table-column>
    <el-table-column prop="encode" width="180" label="catalogName"></el-table-column>
    <el-table-column prop="address" width="180" label="catalogCode"></el-table-column>
    <el-table-column>
      <el-button type="primary" round>查看</el-button>
      <el-button type="danger" round>删除</el-button>
    </el-table-column>
  </el-table>
</div>
<div class="block">
  <el-pagination
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
    :current-page="currentPage"
    :page-sizes="[5,10,20,40]"
    :page-size="pageSize"
    layout="total,sizes,prev,pager,next,jumper"
    :total="tableData.length">
  </el-pagination>
</div>

2、Javascript

<script>
export default {
  data () {
    return {
      currentPage: 1,
      pageSize: 4,
      pageCount: 0,
      tableData: [],
      list: [{
        index: 1,
        name: '张三',
        encode: '80000001',
        address: '新疆乌鲁木齐'
      }, {
        index: 1,
        name: '李四',
        encode: '80000002',
        address: '西藏拉霎'
      }, {
        index: 1,
        name: '王麻子',
        encode: '80000003',
        address: '甘肃天水'
      }, {
        index: 1,
        name: '赵六',
        encode: '80000004',
        address: '宁夏银川'
      }, {
        index: 1,
        name: '钱七',
        encode: '80000005',
        address: '内蒙呼和浩特'
      }, {
        index: 1,
        name: '孙八',
        encode: '80000006',
        address: '青海西宁'
      }]
    }
  },
  created: function () {
    this.handleCurrentChange(this.currentPage)
  },
  methods: {
    handleSizeChange: function (size) {
      this.pageSize = size
    },
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage
      this.currentChangePage(this.list, currentPage)
    },
    handlePrevClick: function () {
      if (this.currentPage !== 1) {
        this.currentPage++
      }
    },
    handleNextClick: function () {
      if (this.currentPage <= this.pageCount) {
        this.currentPage--
      }
    },
    currentChangePage (list, currentPage) {
      console.log(list.length)
      console.log(currentPage)
      this.pageCount = (list.length + this.pageSize - 1) / this.pageSize
      console.log(this.pageCount)
      let from = (currentPage - 1) * this.pageSize
      let to = currentPage * this.pageSize
      this.tabledata = []
      for (;from < to; from++) {
        console.log(from)
        console.log(list[from])
        if (list[from]) {
          this.tableData.push(list[from])
        }
      }
    }
  }
}
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大浪淘沙胡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值