PageNation.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div style="position: absolute;bottom: -60px;right: 20px;">
  3. <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[10, 20, 30, 40]"
  4. :small="small" :disabled="disabled" :background="background"
  5. layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
  6. @current-change="handleCurrentChange" />
  7. </div>
  8. </template>
  9. <script>
  10. import { ref, onMounted, toRefs, watch } from 'vue'
  11. import task from '@/api/task'
  12. export default {
  13. props: {
  14. totals: {
  15. type: Number,
  16. required: true,
  17. },
  18. pageNum: {
  19. type: Number,
  20. required: true
  21. },
  22. pageSize: {
  23. type: Number,
  24. required: true
  25. }
  26. },
  27. setup(props, { emit }) {
  28. let currentPage = ref(1)//页码
  29. let pageSize = ref(10)//页数
  30. let small = ref(false)
  31. let disabled = ref(false)
  32. let background = ref(false)
  33. let total = ref(100)//总数
  34. watch(() => props.totals, (newVal) => {
  35. total.value = newVal
  36. })
  37. watch(() => props.pageNum, (newVal) => {
  38. currentPage.value = newVal
  39. console.log(currentPage.value,'watch');
  40. },{
  41. deep:true
  42. })
  43. function reload() {
  44. currentPage.value = props.pageNum
  45. pageSize.value = props.pageSize
  46. total.value = props.totals
  47. console.log(currentPage.value,'页码');
  48. }
  49. function handleSizeChange(e) {//每页条数
  50. pageSize.value = e
  51. task.getTask({
  52. pageno: currentPage.value - 0,
  53. pagesize: pageSize.value - 0
  54. }).then(res => {
  55. total.value = res.count
  56. emit("pageBack", res.data)
  57. })
  58. }
  59. function handleCurrentChange(e) {//页码
  60. currentPage.value = e
  61. task.getTask({
  62. pageno: currentPage.value - 0,
  63. pagesize: pageSize.value - 0
  64. }).then(res => {
  65. total.value = res.count
  66. emit("currentBack",currentPage.value)
  67. emit("pageBack", res.data)
  68. })
  69. }
  70. onMounted(() => {
  71. reload()
  72. })
  73. return {
  74. currentPage,
  75. pageSize,
  76. small,
  77. disabled,
  78. background,
  79. total,
  80. reload,
  81. handleCurrentChange,
  82. handleSizeChange,
  83. }
  84. }
  85. }
  86. </script>
  87. <style lang="scss" scoped></style>