index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <div class="pagination-container">
  3. <el-pagination
  4. :current-page.sync="currentPage"
  5. :page-size.sync="pageSize"
  6. :layout="layout"
  7. :page-sizes="pageSizes"
  8. :total="total"
  9. v-bind="$attrs"
  10. @size-change="handleSizeChange"
  11. @current-change="handleCurrentChange"
  12. />
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. name: 'Pagination',
  18. props: {
  19. total: {
  20. required: true,
  21. type: Number,
  22. },
  23. page: {
  24. type: Number,
  25. default: 1,
  26. },
  27. limit: {
  28. type: Number,
  29. default: 10,
  30. },
  31. pageSizes: {
  32. type: Array,
  33. default() {
  34. return [10, 50, 100, 200]
  35. },
  36. },
  37. layout: {
  38. type: String,
  39. default: 'total, sizes, prev, pager, next, jumper',
  40. },
  41. background: {
  42. type: Boolean,
  43. default: true,
  44. },
  45. autoScroll: {
  46. type: Boolean,
  47. default: true,
  48. },
  49. hidden: {
  50. type: Boolean,
  51. default: false,
  52. },
  53. },
  54. computed: {
  55. currentPage: {
  56. get() {
  57. return this.page
  58. },
  59. set(val) {
  60. this.$emit('update:page', val)
  61. },
  62. },
  63. pageSize: {
  64. get() {
  65. return this.limit
  66. },
  67. set(val) {
  68. this.$emit('update:limit', val)
  69. },
  70. },
  71. },
  72. methods: {
  73. handleSizeChange(val) {
  74. // this.currentPage = 1
  75. // this.$emit('update:page', 1)
  76. this.$emit('pagination', { page: this.currentPage, limit: val })
  77. if (this.autoScroll) {
  78. scrollTo(0, 800)
  79. }
  80. },
  81. handleCurrentChange(val) {
  82. this.$emit('pagination', { page: val, limit: this.pageSize })
  83. if (this.autoScroll) {
  84. scrollTo(0, 800)
  85. }
  86. },
  87. },
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. .pagination-container {
  92. background: #fff;
  93. padding: 5px 15px;
  94. }
  95. .pagination-container.hidden {
  96. display: none;
  97. }
  98. /deep/ .el-pagination {
  99. left: 36%;
  100. position: relative;
  101. // margin-left: -400px;
  102. }
  103. </style>