首页 > 其他分享 >最简单的前端分页---思路就是监听分页变化,然后slice数据源

最简单的前端分页---思路就是监听分页变化,然后slice数据源

时间:2023-09-11 16:12:56浏览次数:40  
标签:slice 分页 val 数据源 resp tableLoading currentPage data

element版本的

背景

有些页面显示数据量不大,或者后端分页比较复杂;不考虑性能情况下前端分页不失为比较好的选择。

实现

技术点:VUE + Element (el-table , el-pagination)

DEMO

<template>
  <div class="app-container">
    <div class="content">
      <el-table
        v-loading="tableLoading"
        :data = "supplierData.slice((currentPage-1)*pageSize,currentPage*pageSize)"
        element-loading-text="拼命加载中"
      >
        <el-table-column prop="supplierId" label="Id" sortable />
        <el-table-column prop="supplierName" label="名称" sortable />
      </el-table>
      <div style="display: flex; justify-content: flex-end;">
        <el-pagination :current-page="currentPage" :page-sizes="[15,50,100,300]" :page-size="pageSize" :total="supplierData.length" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange" @current-change="handleCurrentChange"></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>

export default {
  name: 'Suppliers',
  data() {
    return {
      tableLoading: false,
      supplierData: [],
      currentPage: 1, // 当前页码
      total: 0, // 总条数
      pageSize: 15 // 每页的数据条数
    }
  },
  created() {
    this.search()
  },
  methods: {
    search() {
      this.tableLoading = true
      getSupplier(this.filter).then((resp) => {
        this.tableLoading = false
        if (resp.result) {
          this.supplierData = resp.data
          this.total = resp.data.length
        }
      })
    },
    handleSizeChange(val) {
      this.currentPage = 1
      this.pageSize = val
    },
    handleCurrentChange(val) {
      this.currentPage = val
    }
  }
}
</script>

作者:不语翕
链接:https://www.jianshu.com/p/6ee7253d1229
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

antd-vue版本的,思路类似

标签:slice,分页,val,数据源,resp,tableLoading,currentPage,data
From: https://www.cnblogs.com/cn-oldboy/p/17693787.html

相关文章

  • 配置多数据源
    title:配置多数据源date:2021-03-03categories:Springtags:DataSourse启动类@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,DataSourceTransactionManagerAutoConfiguration.class,JdbcTemplateAutoConfiguration.class})......
  • mybatis-plus中添加的依赖,使用的方法,分页查询中添加的拦截器
    2023-09-10mybatis-plus中添加的依赖<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.0</version></dependency>使用的......
  • 1782_Adobe Reader X实现pdf分页保存
    全部学习汇总:GitHub-GreyZhang/windows_skills:someskillswhenusingwindowssystem.看了一本pdf电子书,觉得其中几页很值得分享。如果分享整本书当然是不错的选择,但是分享整本书很可能会导致一个结局——内容太多别人不会去看!这样想来,分页导出需要分享的部分再进行分享就好......
  • django-普通分页
    views.py代码:defperson_page(request):#从URL中取出参数page,这个参数是"?page=1"形式cur_page_num=request.GET.get('page')#取得PrettyNum中的记录总数total_count=models.PrettyNum.objects.all().count()#设定每一页显示多少条记录on......
  • 在代码中配置乐观锁插件和分页插件
    在代码中配置乐观锁插件和分页插件在代码中配置乐观锁插件和分页插件,您可以按照以下步骤进行操作:配置乐观锁插件:乐观锁插件是MyBatisPlus提供的功能之一,您可以在配置类中进行配置。假设您使用的是SpringBoot,可以创建一个配置类(如MyBatisConfig)并添加@Configuration注解,......
  • django-普通分页实现
    views.py代码:#普通分页功能defperson_page(request):#从URL中取出参数page,这个参数是“page=1”形式cur_page_num=request.GET.get('page')#取得PrettyNum模型中的记录总数total_count=models.PrettyNum.objects.all().count()#设定每......
  • drf—过滤、分页、异常
    session回顾写一个登录接口——保存用户登录状态签发阶段:做了三件事情:1、生成一个随机字符串2、django—session表中插入数据3、把随机字符串以cookie形式返回给前端(存在浏览器的cookie中)认证阶段:前端自动携带cookie到后端,sessionid:随机字符串session的流......
  • drf 分页类
    一、分页类型一1、写一个分页类,继承 PageNumberPaginationweb用这个多http://api.example.org/accounts/?page=4http://api.example.org/accounts/?page=4&page_size=100fromrest_framework.paginationimportPageNumberPagination,LimitOffsetPagination,CursorPagin......
  • drf-排序、过滤、分页、异常处理
    一、排序只有5个接口中的查询所有,才涉及到排序,所以继承GenericViewSet, 使用步骤:1.必须写在继承:GenericAPIView类的视图中才行2.配置类属性:filter_backends=[OrderingFilter]ordering_fields=['id','user_type']#可以排序的字段3.使用:......
  • 过滤,分页,异常处理
    1过滤只针对于查询所有接口必须继承GenericAPIView#安装: pipinstalldjango==3.2.12pipinstalldjango-filter#使用方式:三种 -方式一:内置的#查询方式http://127.0.0.1:8000/books/?search=29#模糊匹配:只要名字中有29或价格中有29都能搜......