需求:后端返回1000条数据,只能前端做分页

template部分:

<div class="CollaborativeAllocation">
    <!-- 表格 -->
    <!-- 分页 -->
    <div class="pagination" v-if="displayedData?.length > 0">
      <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :page-sizes="[100, 200, 300, 400]"
        :size="size"
        :disabled="disabled"
        :background="background"
        layout="total, prev, pager, next,jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>

script部分

import { ref, onMounted, onUnmounted, watchEffect } from 'vue'


const currentPage = ref(1)
const pageSize = ref(10)
const size = ref('default')
const total = ref(0)
const disabled = ref(false)
const background = ref(false)
const tableData = ref([])//后端返回的数据


watchEffect(() => {
  const start = (currentPage.value - 1) * pageSize.value
  const end = start + pageSize.value
  displayedData.value = tableData.value.slice(start, end)
  // console.log(displayedData.value)
})


// 每页条数变化时的处理函数
const handleSizeChange = val => {
  pageSize.value = val
  currentPage.value = 1 // 每次改变每页条数时,将当前页重置为第一页
}
const handleCurrentChange = val => {
  // console.log(`current page: ${val}`)
  currentPage.value = val
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值