美文网首页
3、常数项分类列表加分页功能

3、常数项分类列表加分页功能

作者: wqjcarnation | 来源:发表于2021-11-23 10:16 被阅读0次

目标

  • 列表功能
  • 分页功能

列表功能

第一步,添加成功跳转到列表页

  this.$router.push({path:'/findAllConType'})

第二步 添加路由地址定义:

       {
        path:'/findAllConType',
        name:'FindAllConType',
        component:FindAllConType
    }

第三步 开发列表页

列表选择

image.png

对应的代码拷贝到 FindAllConType.vue页面里

<template>
  <el-table
    ref="multipleTable"
    :data="tableData"
    tooltip-effect="dark"
    style="width: 100%"
    @selection-change="handleSelectionChange">
    <el-table-column
      type="selection"
      width="55">
    </el-table-column>
    <el-table-column
      label="日期"
      width="120">
      <template slot-scope="scope">{{ scope.row.date }}</template>
    </el-table-column>
    <el-table-column
      prop="name"
      label="姓名"
      width="120">
    </el-table-column>
    <el-table-column
      prop="address"
      label="地址"
      show-overflow-tooltip>
    </el-table-column>
  </el-table>

</template>

<script>
  export default {
    data() {
      return {
        tableData: [{
          date: '2016-05-03',
          name: '张三',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-08',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-06',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-07',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }],
        multipleSelection: []
      }
    },

    methods: {
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      }
    }
  }
</script>
<style></style>

分析页面组成

1、数据放到tableData里
2、tableData里的属性与页面通过prop="name"来绑定

接下来的工作至少需要两步
1)页面加载时查询后台获取列表数据
2) 页面获取响应,更新页面

  • 页面

      <template>
        <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            width="55">
          </el-table-column>
          <el-table-column
            label="日期"
            width="120">
            <template slot-scope="scope">{{ scope.row.date }}</template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="姓名"
            width="120">
          </el-table-column>
          <el-table-column
            prop="address"
            label="地址"
            show-overflow-tooltip>
          </el-table-column>
        </el-table>
    
      </template>
    
      <script>
        export default {
          data() {
            return {
              tableData: [],
              multipleSelection: []
            }
          },
          mounted(){
              this.findAll();
          },
          methods: {
            toggleSelection(rows) {
              if (rows) {
                rows.forEach(row => {
                  this.$refs.multipleTable.toggleRowSelection(row);
                });
              } else {
                this.$refs.multipleTable.clearSelection();
              }
            },
            handleSelectionChange(val) {
              this.multipleSelection = val;
            },
            findAll(){
                //用axios请求后台,查询所有数据
                 this.$axios.get('http://localhost:8082/sys/constanttype/findAll',{params: {
                                          currentPage: 2,
                                          pageSize: 5
                                      }}) 
                .then(response=>{
                    //如果响应成功,把列表数据放到tableData里
                    alert(response);
                })
                
            }
            
            
          }
        }
      </script>
      <style></style>
    

后台用pageHelper

1、pom.xml

<!-- mybatis分页插件pagehelper -->
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>1.2.10</version>
</dependency>

2、application.properties

#pagehelper\u5206\u9875\u63D2\u4EF6\u914D\u7F6E
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql

3、controller

@RequestMapping("/findAllPage")
public PageInfo add(PageParam page){
    PageHelper.startPage(page.getPageNumber(), page.getPageSize());
    List<ConstantType> resultList=service.findAll();
    PageInfo pageInfo =new PageInfo(resultList);
    return pageInfo;
}
  • 后台service mapper省略

分页功能

前台完整代码:

    <template>
        <div>
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column
          label="常数类别编码"
          width="120">
          <template slot-scope="scope">{{ scope.row.constantTypeCode }}</template>
        </el-table-column>
        <el-table-column
          prop="constantTypeName"
          label="常数类别名称"
          width="120">
        </el-table-column>
      </el-table>
          <el-pagination
            background
        layout="prev, pager, next"
        @current-change="changePage"
        :page-size="pageSize"
        :total="total">
   </el-pagination>
      </div>
    </template>
    <script>
      export default {
        data() {
          return {
            tableData: [],
            currentPage:1,
            pageSize:5,
            total:0,
            multipleSelection: []
          }
        },
        mounted(){
            this.findAll();
        },
        methods: {
          toggleSelection(rows) {
            if (rows) {
              rows.forEach(row => {
                this.$refs.multipleTable.toggleRowSelection(row);
              });
            } else {
              this.$refs.multipleTable.clearSelection();
            }
          },
          handleSelectionChange(val) {
            this.multipleSelection = val;
          },
          findAll(){
              
              //用axios请求后台,查询所有数据
               this.$axios.get('http://localhost:8082/sys/constanttype/findAll',{params: {
                                        currentPage: this.currentPage,
                                        pageSize: this.pageSize
                                    }}) 
              .then(response=>{
                  //如果响应成功,把列表数据放到tableData里
                  //alert(response);
                  this.tableData=response.data.content;
                  this.total=response.data.totalElements;
                   })
              
          },
          changePage:function(currentPage){
              //alert("下一页");
              //更新当前页页码
              this.currentPage=currentPage;
              //再重新请求后台
              this.findAll();
          }
        }
      }
    </script>
    <style></style>

关键代码

参考element-ui->pagnation分页-带背景的分页

          <el-pagination
  background
  layout="prev, pager, next"
  @current-change="changePage"
  :page-size="pageSize"
  :pager-count="pagerCount"
  :total="total">
</el-pagination>

对应的绑定事件-获取当前页并重新请求

          changePage:function(currentPage){
              //alert("下一页");
              //更新当前页页码
              this.currentPage=currentPage;
              //再重新请求后台
              this.findAll();
          }

data部分新增加了几个属性

     data() {
          return {
            。。。
            currentPage:1,
            pageSize:5,
            total:0,
            pagerCount:0,
            。。。
          }
        }

axios成功的回调函数里更新数据

          findAll(){
              
              //用axios请求后台,查询所有数据
               this.$axios.get('http://localhost:8082/sys/constanttype/findAll',{params: {
                                        currentPage: this.currentPage,
                                        pageSize: this.pageSize
                                    }}) 
              .then(response=>{
                  //如果响应成功,把列表数据放到tableData里
                  //alert(response);
                  this.tableData=response.data.content;
                  this.total=response.data.totalElements;
                  this.pagerCount=response.data.totalPages;
              })
              
          }

测试

image.png
image.png

相关文章

  • 3、常数项分类列表加分页功能

    目标 列表功能 分页功能 列表功能 第一步,添加成功跳转到列表页 第二步 添加路由地址定义: 第三步 开发列表页 ...

  • 十二、MyBatis实现分页功能

    一、本课目标 掌握MyBatis分页实现 二、MyBatis分页功能实现 需求说明: 为用户管理之查询用户列表功能...

  • 3、 基本信息任务分配

    学生分组完成以下功能 常数项管理 科室管理 挂号级别管理(做到常数项里) 结算类别管理 疾病分类管理 病症管理 费...

  • django项目--新闻主页

    新闻主页 一、功能需求分析 1.功能 轮播图 推荐文章列表 文章标签导航 文章列表 分页 二、模型设计 根据功能分...

  • 8、基本信息管理-任务分配

    学生分组完成以下功能 常数项管理(每人必做) 科室管理 挂号级别管理 结算类别管理(合并到常数项里) 疾病分类管理...

  • 零基础使用Django2.0.1打造在线教育网站(十六):列表分

    写在前面 本篇笔记我们将介绍列表分页,分类筛选,课程机构排序以及学习人数和课程人数排名等功能的实现。 本篇笔记对应...

  • dedecms 首页实现分页

    这个是利用自由列表来实现,做此标记 如何通过自由列表功能实现DedeCMS织梦首页分页 1 2 3 4 5 6 7...

  • element-ui 组件扩展 - 组合table 和 pagi

    element-ui 中table 组件不带有分页,必须配合pagination组件来完成表格的分页功能,这对列表...

  • 2.任务列表功能

    3个部分(左,中,右) 左边:分类栏 中:任务列表 右:任务详情 任务列表 实现功能 默认指针:currentC...

  • 1.分类栏功能

    3个部分(左,中,右) 左边:分类栏 中:任务列表 右:任务详情 分类栏 实现功能 默认指针:currentCh...

网友评论

      本文标题:3、常数项分类列表加分页功能

      本文链接:https://www.haomeiwen.com/subject/ngfwtrtx.html