vue實(shí)現(xiàn)分頁(yè)功能
本文實(shí)例為大家分享了vue實(shí)現(xiàn)分頁(yè)功能的具體代碼,供大家參考,具體內(nèi)容如下
- 使用組件分頁(yè)
- 自己寫分頁(yè)
一、組件分頁(yè)
<el-pagination
layout="prev, pager, next"
@current-change="changePageNum"
:current-page="pageNum"
:page-size="pageSize"
:total="total">
</el-pagination>
data(){
return{
tableData: [],
total: 0,//總數(shù)
pageNum: 1,//當(dāng)前頁(yè)
pageSize: 15,//每頁(yè)顯示數(shù)量
}
}
mounted: function () {
this.query();//加載頁(yè)面時(shí),獲取數(shù)據(jù)
},
methods:{
//切換頁(yè)碼
changePageNum: function (val) {
this.pageNum = val;
this.query();
},
//通過(guò)接口,獲取數(shù)據(jù)
query: function () {
var data = {
name: this.name || '',
fleetId: this.FleetId,
pageNum: this.pageNum,//當(dāng)前頁(yè)
pageSize: this.pageSize//查詢個(gè)數(shù)
};
RoleManage.getRole(data)
.then(res => {
var data = res;
if (res.success) {
this.tableData = data.obj.list;
this.total = data.obj.total;
this.name ='';
} else {
this.$message('查詢失敗');
}
}).catch(err => {
// 異常情況
console.log(err);
});
},
}
組件分頁(yè)效果

二、自己構(gòu)建分頁(yè)
有些時(shí)候需要根據(jù)需求自己寫分頁(yè)
1、分頁(yè)樣式

2、上下切頁(yè)
//調(diào)度-系統(tǒng)通訊錄分頁(yè)
dispatchCourentPage: 1,
//調(diào)度-系統(tǒng)通訊錄當(dāng)前選中標(biāo)簽標(biāo)記
dispatchCourentIndex: 1,
//調(diào)度-系統(tǒng)通訊錄更多標(biāo)記項(xiàng):組id
dispatchMorecommandGroupId: '',
dispatchTotlePage: 0,
//上頁(yè)
handleLastPage() {
if (this.dispatchCourentPage === 1) return;
this.dispatchCourentPage -= 1;
let index = this.dispatchCourentIndex;
if (this.dispatchMorecommandGroupId != '') {
this.queryBookMoreBygroupId(this.dispatchMorecommandGroupId);
} else {
this.queryBookmember(index);
}
},
//下頁(yè)
handleNextPage() {
if (this.dispatchCourentPage === this.dispatchTotlePage) return;
this.dispatchCourentPage += 1;
let index = this.dispatchCourentIndex;
if (this.dispatchMorecommandGroupId != '') {
this.queryBookMoreBygroupId(this.dispatchMorecommandGroupId);
} else {
this.queryBookmember(index);
}
}
三、使用監(jiān)聽屬性控制分頁(yè)顯示
computed: {
limitData() {
let data = [...this.table1Datas];
return data;
},
// 因?yàn)橐獎(jiǎng)討B(tài)計(jì)算總頁(yè)數(shù),所以還需要一個(gè)計(jì)算屬性來(lái)返回最終給 Table 的 data
dataWithPage() {
const data = this.limitData;
const start = this.current * this.size - this.size;
const end = start + this.size;
return [...data].slice(start, end);
},
}
四、js控制分頁(yè),計(jì)算總頁(yè)數(shù)
方法1
/**
*根據(jù)數(shù)據(jù)條數(shù)與每頁(yè)多少條數(shù)據(jù)計(jì)算頁(yè)數(shù)
* totalnum 數(shù)據(jù)條數(shù)
* limit 每頁(yè)多少條
*/
pageCount(totalnum, limit) {
return totalnum > 0 ? ((totalnum < limit) ? 1 : ((totalnum % limit)
? (parseInt(totalnum / limit) + 1)
: (totalnum / limit))) : 0;
},
方法2
/**
* 分頁(yè)的總頁(yè)數(shù)算法
* 總記錄數(shù):totalRecord
* 每頁(yè)最大記錄數(shù):maxResult
*/
function pageCount() {
totalPage = (totalRecord + maxResult -1) / maxResult;
}
方法3 推薦
totalPage = Math.floor((totalRecord +maxResult -1) /maxResult );
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
使用vue打包時(shí)vendor文件過(guò)大或者是app.js文件很大的問(wèn)題
這篇文章主要介紹了使用vue打包時(shí)vendor文件過(guò)大或者是app.js文件很大問(wèn)題的解決方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-06-06
vue3中的數(shù)據(jù)劫持的最新實(shí)現(xiàn)方案的proxy示例詳解
Vue3中使用Proxy實(shí)現(xiàn)數(shù)據(jù)劫持,解決了Vue2中數(shù)組和對(duì)象劫持的遺留問(wèn)題,Proxy可以修改某些操作的默認(rèn)行為,通過(guò)get和set方法實(shí)現(xiàn)數(shù)據(jù)的劫持和保護(hù)機(jī)制,感興趣的朋友跟隨小編一起看看吧2024-11-11
vue中使用[provide/inject]實(shí)現(xiàn)頁(yè)面reload的方法
這篇文章主要介紹了在vue中使用[provide/inject]實(shí)現(xiàn)頁(yè)面reload的方法,文中給大家提到了在vue中實(shí)現(xiàn)頁(yè)面刷新不同的方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09
vue3 座位選座矩陣布局的實(shí)現(xiàn)方法(可點(diǎn)擊選中拖拽調(diào)換位置)
由于公司項(xiàng)目需求需要做一個(gè)線上設(shè)置考場(chǎng)相關(guān)的座位布局用于給學(xué)生考機(jī)排號(hào)考試,實(shí)現(xiàn)教室考場(chǎng)座位布局的矩陣布局,可點(diǎn)擊選中標(biāo)記是否有座無(wú)座拖拽調(diào)換位置橫向縱向排列,本文給大家分享實(shí)現(xiàn)代碼,一起看看吧2023-11-11
Vue中的驗(yàn)證登錄狀態(tài)的實(shí)現(xiàn)方法
這篇文章主要介紹了Vue中的驗(yàn)證登錄狀態(tài)的實(shí)現(xiàn)方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-03-03

