index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div :class="{'hidden':hidden}" class="pagination-container">
  3. <el-pagination
  4. :background="background"
  5. :current-page.sync="currentPage"
  6. :page-size.sync="pageSize"
  7. :layout="layout"
  8. :total="total"
  9. v-bind="$attrs"
  10. @size-change="handleSizeChange"
  11. @current-change="handleCurrentChange"/>
  12. </div>
  13. </template>
  14. <script>
  15. import { scrollTo } from '@/utils/scrollTo'
  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: 20
  30. },
  31. pageSizes: {
  32. type: Array,
  33. default() {
  34. return [10, 20, 30, 50]
  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.$emit('pagination', { page: this.currentPage, limit: val })
  75. if (this.autoScroll) {
  76. scrollTo(0, 800)
  77. }
  78. },
  79. handleCurrentChange(val) {
  80. this.$emit('pagination', { page: val, limit: this.pageSize })
  81. if (this.autoScroll) {
  82. scrollTo(0, 800)
  83. }
  84. }
  85. }
  86. }
  87. </script>
  88. <style scoped>
  89. .pagination-container {
  90. background: #fff;
  91. padding: 32px 16px;
  92. }
  93. .pagination-container.hidden {
  94. display: none;
  95. }
  96. .pagination-container {
  97. text-align: right;
  98. }
  99. </style>