vue3 el-pagination 將組件中英文‘goto’ 修改 為 中文到‘第幾’
vue3 el-pagination 將組件中英文‘goto’ 修改 為 中文到‘第幾’
效果如圖:

要求:將英文中Go to 改為到第幾

操作如下:
<template>
<div class="paging">
<el-config-provider :locale="zhCn"> // 注意:這是重要部分
<el-pagination //分頁(yè)組件根據(jù)官網(wǎng)
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>
// 在調(diào)用 分頁(yè)組件el-pagination的頁(yè)面:
import { ElConfigProvider } from 'element-plus'
import zhCn from 'element-plus/es/locale/lang/zh-cn';
zhCn.el.pagination.goto = "到第"
</script>補(bǔ)充:
vue3項(xiàng)目之Pagination 組件
Pagination 組件
官方文檔:https://element-plus.gitee.io/zh-CN/component/pagination.html
我們把分頁(yè)器封裝成一個(gè)公共組件,普通分頁(yè)器只需要兩個(gè)參數(shù):
選擇一:page-size 每頁(yè)的數(shù)量 + total 總數(shù)量
選擇二:page-count 總頁(yè)數(shù) + total 總數(shù)量
外加一個(gè)回調(diào)函數(shù):current-change 當(dāng)點(diǎn)擊分頁(yè)器時(shí)就會(huì)觸發(fā)
Pagination 組件模板
<script setup lang="ts">
import { ElLoading } from 'element-plus'
const emits = defineEmits<{
(e: 'pageChange', num: number): void
}>()
const props = defineProps<{
total: number,
pageSize: number
}>()
// 切換頁(yè)面回調(diào)函數(shù)
function currentChange(p: any) {
const loading = ElLoading.service({
lock: true,
text: 'Loading',
background: 'rgba(255, 255, 255, 0.7)',
})
// 調(diào)用父組件切換頁(yè)面回調(diào)函數(shù)
emits('pageChange', p)
setTimeout(() => { loading.close() }, 500)
}
</script>
<template>
<el-pagination
:page-size="pageSize"
:total="total"
@current-change="currentChange"
顯示屬性
layout="prev, pager, next"
hide-on-single-page
next-text="下一頁(yè)"
prev-text="上一頁(yè)"
/>
</template>
<style scoped>
.el-pagination {
margin: 30px auto;
justify-content: center;
}
</style>父組件引用
// 從 vuex 中獲取參數(shù)(也可以直接在組件中定義)
const roomList = computed(() => store.state.roomList)
const roomTotal = computed(() => store.state.roomTotal)
const roomPageSize = computed(() => store.state.roomPageSize)
// home頁(yè)數(shù)改變回調(diào)函數(shù)
async function roomPageChange(pageNo: any) {
const loading = ElLoading.service({
lock: true,
text: 'Loading',
background: 'rgba(255, 255, 255, 0.7)',
})
page.value = pageNo
await store.dispatch('getRoomList', { pageNo, cityCode: city.value })
setTimeout(() => { loading.close() }, 500)
}<!-- 分頁(yè)器 -->
<Pagination
@pageChange="roomPageChange"
:total="roomTotal" :pageSize="roomPageSize"
/>發(fā)送請(qǐng)求的過(guò)程
在 vuex 發(fā)送請(qǐng)求獲取數(shù)據(jù),保存數(shù)據(jù)列表及數(shù)據(jù)總數(shù)。例如發(fā)送一個(gè)搜索請(qǐng)求,參數(shù):當(dāng)前頁(yè)數(shù)、每頁(yè)數(shù)量等等,獲取的數(shù)據(jù)中會(huì)包含數(shù)據(jù)總數(shù),所以總頁(yè)數(shù)會(huì)自動(dòng)計(jì)算,只需要確定每頁(yè)數(shù)量和數(shù)據(jù)總數(shù)就行。
到此這篇關(guān)于vue3 el-pagination 將組件中英文‘goto’ 修改 為 中文到‘第幾’的文章就介紹到這了,更多相關(guān)vue3 el-pagination英文改為中文內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
前端vue+express實(shí)現(xiàn)文件的上傳下載示例
本文主要介紹了前端vue+express實(shí)現(xiàn)文件的上傳下載示例,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12
vue2項(xiàng)目導(dǎo)出操作實(shí)現(xiàn)方法(后端接口導(dǎo)出、前端直接做導(dǎo)出)
這篇文章主要給大家介紹了關(guān)于vue2項(xiàng)目導(dǎo)出操作實(shí)現(xiàn)方法的相關(guān)資料,文中介紹的是后端接口導(dǎo)出、前端直接做導(dǎo)出,通過(guò)代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-05-05
vue實(shí)現(xiàn)移動(dòng)端觸屏拖拽功能
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)移動(dòng)端觸屏拖拽功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-08-08
Vue3+elementPlus中 樹(shù)形控件封裝的實(shí)現(xiàn)
本文主要介紹了Vue3+elementPlus中 樹(shù)形控件封裝的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2025-04-04

