Vue+ElementUi实现分页效果

注:后台我是用pageHelper分页插件做的
效果图:
在这里插入图片描述

首先配置依赖

<!--pageHelper分页-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.13</version>
        </dependency>

在控制器中:


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/drug")
@CrossOrigin
public class DrugController {


    @Autowired
    private DrugService drugService;

    //查询数据
    @RequestMapping("queryDrug")
    public PageInfo queryDrug(Integer currentPage, Integer pageSize) {
     
        //调用PageHelper.startPage()进行分页
       PageHelper.startPage(currentPage,pageSize);
        //查询数据   直接查询就行
       List<Drug>drugList=drugService.queryDrug();
        //将数据返回前端
       PageInfo pageInfo=new PageInfo(drugList);
       return pageInfo;
    }
}


App.Vue页面代码

<template>
   <div id="app">
    <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 fixed prop="id" label="序号">
        <!--如果想要对当前字段进行转换,需要用到template-->
        <template slot-scope="scope">{{scope.$index+1}}</template>
      </el-table-column>
        <el-table-column prop="drugName" label="药品名称" ><template slot-scope="scope">{{ scope.row.drugName }}</template></el-table-column>
        <el-table-column prop="drugPrice" label="药品价格" ><template slot-scope="scope">{{ scope.row.drugPrice }}</template></el-table-column>
        <el-table-column prop="drugSales" label="药品销量" ><template slot-scope="scope">{{ scope.row.drugSales }}</template></el-table-column>
        <el-table-column prop="drugStock" label="药品库存" ><template slot-scope="scope">{{ scope.row.drugStock }}</template></el-table-column>
        <el-table-column prop="isOTC" label="是否处方药" show-overflow-tooltip>
          <template slot-scope="scope">{{scope.row.isOTC == null ? "" : scope.row.isOTC == 1?"是":"否"}}</template>
        </el-table-column>
        <el-table-column prop="person" label="适用人群" show-overflow-tooltip>
          <template slot-scope="scope">{{scope.row.person == null ? "" : scope.row.person.replace("1","小孩").replace("2","少年").replace("3","青年").replace("4","中年").replace("5","老年").replace("6","僵尸")}}</template>
        </el-table-column>
        <el-table-column prop="areaName" label="地区" ></el-table-column>
        <el-table-column prop="brandName" label="品牌" ></el-table-column>
        <el-table-column prop="producedDate" label="生产时间" ><template slot-scope="scope">{{ scope.row.producedDate }}</template></el-table-column>
        <el-table-column prop="createtime" label="创建时间" ><template slot-scope="scope">{{ scope.row.createtime }}</template></el-table-column>
        <el-table-column prop="updatetime" label="修改时间" ><template slot-scope="scope">{{ scope.row.updatetime }}</template></el-table-column>
        <el-table-column prop="photo" label="图片" show-overflow-tooltip>
          <template slot-scope="scope"><img :src="scope.row.photo"/></template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
            <el-button type="text" size="small">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>

    <!--分页-->
       <el-pagination
       @size-change="handleSizeChange"
       @current-change="handleCurrentChange"
       :current-page="1"
       :page-sizes="[5, 10, 15, 20]"
       :page-size="5"
       layout="total, sizes, prev, pager, next, jumper"
       :total="total">
      </el-pagination>
  </div>
</template>

<script>
  export default {
     name:'App',
    created(){
      this.queryDrug();

    },
    data(){
      return {
        tableData:[],
        multipleSelection: [],
        total:0,
        currentPage:1,
        pageSize:5
      }
    },
    methods:{
      //查询
      queryDrug:function () {
        var _this = this;
        this.$axios.get("http://localhost:8080/drug/queryDrug?currentPage="+this.currentPage+"&pageSize="+this.pageSize).then(function (result) {
          _this.tableData = result.data.list;
          _this.total=result.data.total;
        })
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      //每页条数
      handleSizeChange(val){
        this.pageSize=val;
        this.queryDrug();
      },
      //当前页
      handleCurrentChange(val){
        this.currentPage=val;
        this.queryDrug();
      }
    }
  }
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

jq1223

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

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

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

打赏作者

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

抵扣说明:

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

余额充值