vue3封裝el-pagination分頁(yè)組件的完整代碼
更新時(shí)間:2024年02月26日 09:47:02 作者:PXY_J
這篇文章主要介紹了vue3封裝el-pagination分頁(yè)組件的完整代碼,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
1、效果如圖:
2、分頁(yè)組件代碼:
<template> <div class="paging"> <el-config-provider :locale="zhCn"> <el-pagination v-model:current-page="page.currentPage" v-model:page-size="page.pageSize" :background="page.background" :layout="page.layout" :total="page.total" @size-change="page.handleSizeChange" @current-change="page.handleCurrentChange" /> </el-config-provider> </div> </template> <script setup> import { ElConfigProvider } from 'element-plus' import zhCn from 'element-plus/es/locale/lang/zh-cn'; zhCn.el.pagination.goto = "到第" const props = defineProps({ total: { required: true, type: Number, default: 300 }, // 當(dāng)前頁(yè)數(shù) currentPage: { type: Number, default: 1 }, // 分頁(yè) pageSize: { type: Array, default: () => { return [10, 20, 30, 50, 100] } }, limit: { type: Number, default: 10 }, layout: { type: String, default: 'total, sizes, prev, pager, next, jumper' }, background: { type: Boolean, default: () => { return true }, }, }); const emit = defineEmits(); const currentPage = computed({ get() { return props.currentPage }, set(val) { emit('update:currentPage', val) } }) const pageSize = computed({ get() { return props.limit }, set(val) { emit('update:limit', val) } }) const page = reactive({ background:props.background, currentPage:props.currentPage, pageSize:props.pageSize[0], layout:props.layout, total:props.total, handleSizeChange:(val)=>{ console.log(`${val} items per page`) emit('handleSizeChange', val); }, handleCurrentChange:(val)=>{ console.log(`current page: ${val}`) emit('handleCurrentChange', val); } }); </script> <style lang="scss" scoped> </style>
3、使用代碼:
**結(jié)構(gòu):** <template> <Paging :current-page="page.currentPage" :page-size="page.pageSize" :background="page.background" :layout="page.layout" :total="page.total" :limit="page.limit" @handleSizeChange="page.handleSizeChange" @handleCurrentChange="page.handleCurrentChange" ></Paging> </template> **js:** <script setup> import Paging from "@/components/paging";//引入分頁(yè)組件 const page = reactive({ layout:'prev, pager, next, jumper', currentPage:1, limit:10, total:300, handleSizeChange:(val)=>{ page.pageSize = val }, handleCurrentChange:(val)=>{ page.currentPage = val } }) </script>
到此這篇關(guān)于vue3封裝el-pagination分頁(yè)組件的文章就介紹到這了,更多相關(guān)vue3封裝el-pagination內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue使用once修飾符,使事件只能觸發(fā)一次問(wèn)題
這篇文章主要介紹了vue使用once修飾符,使事件只能觸發(fā)一次問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-05-05Vue3項(xiàng)目中引入html頁(yè)面的方法舉例
這篇文章主要給大家介紹了關(guān)于Vue3項(xiàng)目中引入html頁(yè)面的相關(guān)資料,Vue3是一個(gè)JavaScript框架,通常我們使用它來(lái)構(gòu)建單頁(yè)應(yīng)用程序(SPA),如果你想在HTML頁(yè)面中使用Vue3,可以參考這篇文章,需要的朋友可以參考下2023-09-09element-ui中el-upload多文件一次性上傳的實(shí)現(xiàn)
這篇文章主要介紹了element-ui中el-upload多文件一次性上傳的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12