Pagination.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <el-pagination
  3. @size-change="handleSizeChange"
  4. @current-change="handleCurrentChange"
  5. :current-page.sync="page"
  6. :page-sizes="pageSizes"
  7. :page-size="size"
  8. layout="total, sizes, prev, pager, next, jumper"
  9. :total="total">
  10. </el-pagination>
  11. </template>
  12. <script>
  13. export default {
  14. name: 'Pagination',
  15. props: {
  16. pageSizes: {
  17. type: Array,
  18. default: () => [],
  19. },
  20. codePage: {
  21. type: String,
  22. default: 'page'
  23. },
  24. codeSize: {
  25. type: String,
  26. default: 'size'
  27. },
  28. codeTotal: {
  29. type: String,
  30. default: 'total'
  31. }
  32. },
  33. inject: {
  34. paginationServiceData: {
  35. type: Object,
  36. default: () => {
  37. },
  38. },
  39. tableServiceData: {
  40. type: Object,
  41. default: () => {
  42. },
  43. },
  44. },
  45. computed: {
  46. page: {
  47. get() {
  48. return this.paginationServiceData[this.codePage];
  49. },
  50. set(val) {
  51. this.paginationServiceData[this.codePage] = val;
  52. },
  53. },
  54. size: {
  55. get() {
  56. return this.paginationServiceData[this.codeSize];
  57. },
  58. set(val) {
  59. this.paginationServiceData[this.codeSize] = val;
  60. },
  61. },
  62. total: {
  63. get() {
  64. return this.paginationServiceData[this.codeTotal];
  65. },
  66. set(val) {
  67. this.this.paginationServiceData[this.codeTotal] = val;
  68. },
  69. },
  70. },
  71. watch: {
  72. total(newVal) {
  73. if (newVal >= this.size && !this.tableServiceData.myData.length && this.page > 1) {
  74. this.page--;
  75. this.$emit('current-page', this.page);
  76. }
  77. },
  78. },
  79. methods: {
  80. handleSizeChange(val) {
  81. this.$emit('size-change', val);
  82. },
  83. handleCurrentChange(val) {
  84. this.$emit('current-page', val);
  85. },
  86. },
  87. };
  88. </script>
  89. <style scoped>
  90. </style>