当前位置:   article > 正文

自定义自己想要的样式的分页器,使用Element UI中Pagination 分页器组件,封装成自己想要的组件。_elemenui自定义分页

elemenui自定义分页

目标,分页器的样式,控制分页器的左右切换的按钮,增加跳到首页与尾页功能

主要想改变选中的颜色,以及增加自定义功能,左右切换的按钮可以使用自己想用的图片,这里使用element ui的图标

直接上代码了

HTML:

  1. <template>
  2. <div class="pagination">
  3. <div
  4. class="pageWord firstPage"
  5. v-if="currentPage !== 1"
  6. @click="toFirstPage()"
  7. >
  8. 首页
  9. </div>
  10. <div class="left-arrow" v-if="currentPage !== 1" @click="prevPage()">
  11. <i class="el-icon-arrow-left" style="color: #1890ff; font-size: 24px"></i>
  12. </div>
  13. <el-pagination
  14. @size-change="handleSizeChange"
  15. @current-change="handleCurrentChange"
  16. :current-page.sync="currentPage"
  17. :page-size="pageSize"
  18. layout=" pager"
  19. :total="total"
  20. >
  21. </el-pagination>
  22. <div
  23. class="right-arrow"
  24. @click="nextPage()"
  25. v-if="currentPage !== Math.ceil(total / pageSize)"
  26. >
  27. <i class="el-icon-arrow-right" style="color: #1890ff; font-size: 24px"></i>
  28. </div>
  29. <div
  30. class="pageWord lastPage"
  31. v-if="currentPage !== Math.ceil(total / pageSize)"
  32. @click="toLastPage()"
  33. >
  34. 尾页
  35. </div>
  36. </div>
  37. </template>

JS,主要通过控制 当前页currentPage数据来实现

  1. <script>
  2. export default {
  3. data() {
  4. return {
  5. currentPage: 1,
  6. pageSize: 10,
  7. total: 100
  8. }
  9. },
  10. methods: {
  11. // 跳转到首页
  12. toFirstPage() {
  13. this.currentPage = 1
  14. },
  15. // 跳转到尾页
  16. toLastPage() {
  17. this.currentPage = Math.ceil(this.total / this.pageSize)
  18. },
  19. // 左切换
  20. prevPage() {
  21. if (this.currentPage === 1) {
  22. return
  23. } else {
  24. this.currentPage--
  25. }
  26. },
  27. // 右切换
  28. nextPage() {
  29. if (this.currentPage === Math.ceil(this.total / this.pageSize)) {
  30. return
  31. } else {
  32. this.currentPage++
  33. }
  34. },
  35. handleSizeChange(val) {
  36. console.log(`每页 ${val} 条`)
  37. },
  38. handleCurrentChange(val) {
  39. console.log(`当前页: ${val}`)
  40. }
  41. }
  42. }
  43. </script>

CSS中主要通过/ deep / 深度查找元素 修改样式

  1. <style lang="scss" scoped>
  2. .pagination {
  3. display: flex;
  4. justify-content: flex-end;
  5. align-items: center;
  6. position: relative;
  7. left: -10px;
  8. transform: all 0.4s;
  9. .pageWord {
  10. font-size: 22px;
  11. font-weight: 400;
  12. color: #1890ff;
  13. cursor: pointer;
  14. }
  15. .firstPage {
  16. margin-right: 10px;
  17. }
  18. .lastPage {
  19. margin-left: 10px;
  20. }
  21. .left-arrow {
  22. margin-right: 20px;
  23. }
  24. .right-arrow {
  25. margin-left: 20px;
  26. }
  27. .left-arrow,
  28. .right-arrow {
  29. cursor: pointer;
  30. }
  31. /deep/ .el-pagination {
  32. .el-pager li:hover {
  33. color: #1890ff;
  34. }
  35. .el-pager {
  36. .number {
  37. color: #858585;
  38. font-size: 22px;
  39. cursor: pointer;
  40. transition: all 0.4s;
  41. margin-left: 17px;
  42. }
  43. .number.active {
  44. font-size: 30px;
  45. color: #1890ff;
  46. }
  47. .number.active::after {
  48. content: '/';
  49. }
  50. .el-icon-more {
  51. margin-left: 20px;
  52. }
  53. }
  54. }
  55. }
  56. </style>

实现结果:

 

 

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号