• vue3封装分页组件


    1.新建Pagination文件以及该文件夹下新建index.vue

    2.在index.vue文件中编写一下代码

    1. <script setup>
    2. import { scrollTo } from '@/utils/scroll-to'
    3. const props = defineProps({
    4. total: {
    5. required: true,
    6. type: Number
    7. },
    8. page: {
    9. type: Number,
    10. default: 1
    11. },
    12. limit: {
    13. type: Number,
    14. default: 20
    15. },
    16. pageSizes: {
    17. type: Array,
    18. default() {
    19. return [30, 60, 100]
    20. }
    21. },
    22. // 移动端页码按钮的数量端默认值5
    23. pagerCount: {
    24. type: Number,
    25. default: document.body.clientWidth < 992 ? 5 : 7
    26. },
    27. layout: {
    28. type: String,
    29. default: 'total, sizes, prev, pager, next, jumper'
    30. },
    31. background: {
    32. type: Boolean,
    33. default: true
    34. },
    35. autoScroll: {
    36. type: Boolean,
    37. default: true
    38. },
    39. hidden: {
    40. type: Boolean,
    41. default: false
    42. }
    43. })
    44. const emit = defineEmits();
    45. const currentPage = computed({
    46. get() {
    47. return props.page
    48. },
    49. set(val) {
    50. emit('update:page', val)
    51. }
    52. })
    53. const pageSize = computed({
    54. get() {
    55. return props.limit
    56. },
    57. set(val){
    58. emit('update:limit', val)
    59. }
    60. })
    61. function handleSizeChange(val) {
    62. if (currentPage.value * val > props.total) {
    63. currentPage.value = 1
    64. }
    65. emit('pagination', { page: currentPage.value, limit: val })
    66. if (props.autoScroll) {
    67. scrollTo(0, 800)
    68. }
    69. }
    70. function handleCurrentChange(val) {
    71. emit('pagination', { page: val, limit: pageSize.value })
    72. if (props.autoScroll) {
    73. scrollTo(0, 800)
    74. }
    75. }
    76. script>
    77. <style scoped>
    78. .demo-pagination-block {
    79. position: fixed;
    80. bottom: 20px;
    81. right: 20px;
    82. width: 50vw;
    83. padding-bottom: 20px;
    84. background: #fff;
    85. z-index: 99;
    86. .pagination-container {
    87. margin-top: 0;
    88. }
    89. }
    90. .pagination-container {
    91. background: #fff;
    92. padding: 0 16px 20px;
    93. }
    94. .pagination-container.hidden {
    95. display: none;
    96. }
    97. style>

    3.使用封装的组件

    1. <div class="demo-pagination-block">
    2. <pagination :total="data.total" v-model:page="searchParams.pageNum" v-model:limit="searchParams.pageSize"
    3. @pagination="getList" />
    4. div>
    1. import { pageList } from '@/api/dataScheduling/portDataList'
    2. const searchParams = reactive({
    3. containerNo: '', // 集装箱号
    4. searchDate: '', // 筛选时间
    5. dataStatus: '', // 状态
    6. shipName: '', // 船名
    7. destinationPort: '', // 目的港
    8. pageNum: 1, // 页码
    9. pageSize: 30, // 条数
    10. });
    11. const data = reactive({
    12. total: 10, // 总条数
    13. tableData: [], // 数据列表
    14. });
    15. onMounted(() => {
    16. getList();
    17. });
    18. // 获取数据列表
    19. const getList = () => {
    20. let params = { ...searchParams }
    21. pageList(params).then(res => {
    22. console.log('获取列表', res);
    23. data.tableData = res.rows
    24. data.total = res.total
    25. })
    26. };

  • 相关阅读:
    c++视觉图像线性混合
    postgresql简单sql
    SpringBoot工作开发场景实践
    Spark基础【RDD单Value类型转换算子】
    并购支付牌照中金支付90.01%股权该注意哪些风险
    nvidia-smi指令报错:Failed to initialize NVML: Driver 解决
    关于计算机网络
    解读 | 自动驾驶系统中的多视点三维目标检测网络
    浅谈Oracle数据库调优(2)
    设计模式之【职责链模式】
  • 原文地址:https://blog.csdn.net/2202_75509848/article/details/133792704