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