index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <div class="c-pagination l-flex__none">
  3. <el-pagination
  4. :current-page.sync="currentPage"
  5. :page-size.sync="pageSize"
  6. :page-sizes="pageSizes"
  7. :pager-count="5"
  8. :total="Number(total)"
  9. :layout="layout"
  10. :background="background"
  11. hide-on-single-page
  12. v-bind="$attrs"
  13. @size-change="onSizeChange"
  14. @current-change="onCurrentChange"
  15. />
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. name: 'Pagination',
  21. props: {
  22. total: {
  23. required: true,
  24. type: [Number, String]
  25. },
  26. page: {
  27. type: Number,
  28. default: 1
  29. },
  30. limit: {
  31. type: Number,
  32. default: 20
  33. },
  34. pageSizes: {
  35. type: Array,
  36. default () {
  37. return [10, 20, 50]
  38. }
  39. },
  40. layout: {
  41. type: String,
  42. // sizes
  43. default: 'total, prev, pager, next, jumper'
  44. },
  45. background: {
  46. type: [Boolean, String],
  47. default: true
  48. }
  49. },
  50. computed: {
  51. currentPage: {
  52. get () {
  53. return this.page
  54. },
  55. set (val) {
  56. this.$emit('update:page', val)
  57. }
  58. },
  59. pageSize: {
  60. get () {
  61. return this.limit
  62. },
  63. set (val) {
  64. this.$emit('update:limit', val)
  65. }
  66. }
  67. },
  68. methods: {
  69. onSizeChange (val) {
  70. this.$emit('pagination', { page: this.currentPage, limit: val })
  71. },
  72. onCurrentChange (val) {
  73. this.$emit('pagination', { page: val, limit: this.pageSize })
  74. }
  75. }
  76. }
  77. </script>
  78. <style lang="scss" scoped>
  79. .c-pagination {
  80. padding-top: $spacing;
  81. text-align: center;
  82. &:empty {
  83. display: none;
  84. }
  85. ::v-deep .el-pagination.is-background .el-pager li:not(.disabled).active {
  86. background-color: $blue;
  87. }
  88. }
  89. </style>