当前位置: 首页 > article >正文

Naive UI 分页组件二次封装

组件封装代码如下:


 
<script setup lang="ts">
import { computed } from "vue";
const props = defineProps({
    size: {
        type: String,
        default() {
            return "medium";
        },
    },
    total: {
        type: Number,
        required: true,
    },
    page: {
        // 当前页码
        type: Number,
        default: 1,
    },
    limit: {
        type: Number,
        default: 10,
    },
});
const emit = defineEmits();
const currentPage = computed({
    set(val) {
        emit("update:page", val);
    },
    get() {
        return props.page;
    },
});
const pageSize = computed({
    set(val) {
        emit("update:limt", val);
    },
    get() {
        return props.limit;
    },
});
let handleCurrentChange = (page: any) => {
    emit("pagination", {
        page: page,
        limit: pageSize.value,
    });
};
let handleSizeChange = (page: any) => {
    emit("pagination", {
        currentPage: currentPage.value,
        limit: page,
    });
};
</script>

<template>
    <div>
        <n-pagination
            v-model:page="currentPage"
            v-model:page-size="pageSize"
            :size="size"
            :page-sizes="[10, 20, 30, 40]"
            show-quick-jumper
            show-size-picker
            @update:page="handleCurrentChange"
            @update:page-size="handleSizeChange"
            :item-count="total"
        >
			<template #prefix>
				共{{ total }}条数据
			</template>
			<template #goto>到</template>
        	<template #suffix>
                <span class="goto-label">页</span>
                <n-button size="small" type="primary" @click="handleCurrentChange(currentPage)">确定</n-button>
            </template>
        </n-pagination>
    </div>
</template>

<style scoped></style>

使用代码如下:

<script setup lang="ts">
import Pagination from '@/components/Pagination/index.vue'

const page = ref(4)
const pageSize = ref(10)
const totalCount = ref(999)

const pageChange = (val) => {
    page.value = val.page
    pageSize.value = val.limit
}
</script>

<template>
    <n-space>
    <div class="flex items-center justify-end mt-[50px]">
              <pagination
                v-model:page="page"
                v-model:limit="pageSize"
                v-show="totalCount > 0"
                :total="totalCount"
                @pagination="pageChange"
              ></pagination>
      </div>
        <!-- <pagination :page="page" @changePage="pageFn" :totalCount="totalCount"></pagination> -->
    </n-space>
</template>

<style scoped lang="scss"></style>


http://www.kler.cn/a/450909.html

相关文章:

  • Dubbo简单总结
  • 【蓝桥杯——物联网设计与开发】基础模块8 - RTC
  • GitPuk安装配置指南
  • LEC: 基于Transformer中间层隐藏状态的高效特征提取与内容安全分类方法
  • 武汉做网站优化推广效果的科学评估方法
  • redis库基础知识
  • SpringBoot开发——Spring Boot 的9大类常用注解
  • 【XR】ATW
  • LeetCode 1705.吃苹果的最大数目:贪心(优先队列) - 清晰题解
  • Python+QQ邮箱调用定时监控——以网站监测为例
  • Z轴方向二维图像插值形成三维图像的算法及其优劣分析
  • Jmeter 分布式压测部署--常见坑以及解决方案
  • C++简明教程(10)(初识类)
  • acme ssl证书自动续签 nginx
  • 基于 kubeadm 安装 Kubernetes 集群的完整步骤
  • 在 Windows 系统上怎么看sqlserver的驱动版本呢
  • Springboot+Druid(可切换Hikari)+Mybatis-plus+mysql+hive的多数据源项目配置
  • 谷歌浏览器的屏幕截图工具使用指南
  • ubuntu paddle ocr 部署bug问题解决
  • 【Java数据结构】LinkedList