element表格翻頁第2頁從1開始編號(后端從0開始分頁)
更新時間:2019年12月10日 14:21:51 作者:溫言
這篇文章主要介紹了element表格翻頁第2頁從1開始編號(后端從0開始分頁),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
項目中常見的分頁顯示,第二頁從1開始編號,然后在切換分頁的過程中,偶現(xiàn)不對,都是小問題,整理記錄一下,供參考。
template:
... <el-table-column type="index" label="編號" :index="getIndex" width="80px"> </el-table-column> ... <Pagination :total="total" :pageSize="pageSize" :currentPage="currentPage" @sizeChange="sizeChange" @currentChange="currentChange"> </Pagination>
script:
getIndex (index) {
if (this.currentPage==0){
return (this.currentPage) * this.pageSize + index + 1
} else{
return (this.currentPage-1) * this.pageSize + index + 1
}
},
由于后端第一頁是從0開始的,而前端是從第一頁開始,所以需要在當前頁減1。關于分頁,本頁條數(shù)
sizeChange(val){
let that = this;
that.currentPage = 1;
that.pageSize = val;
that.getPageInfo(that.currentPage, val);
},
跳轉頁面
currentChange(val){
let that = this;
that.currentPage = val;
that.getPageInfo(val, that.pageSize);
},
頁面加載數(shù)據(jù)
getUserList(currentPage, pageSize){
let that = this;
that.$axios({
method: 'get',
url: '***',
params: {
currentPage: (currentPage || that.currentPage || 1)-1,
pageSize: pageSize || that.pageSize || 10
},
needInterceptors: true,
showError: true,
loader: true
}).then(function(result){
let data = result && result.data || [];
let page = result && result.pageCont || {};
that.total = page.totalItems || 0;
that.tableData = data;
})
},
試了幾次,這樣寫應該是沒有問題的,也解決了后端傳0開始的問題。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
使用開源Cesium+Vue實現(xiàn)傾斜攝影三維展示功能
這篇文章主要介紹了使用開源Cesium+Vue實現(xiàn)傾斜攝影三維展示,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-07-07
Vue使用el-tree 懶加載進行增刪改查功能的實現(xiàn)
這篇文章主要介紹了Vue使用el-tree 懶加載進行增刪改查,以懶加載的形式展示,目錄根據(jù)需求需要有新增 編輯 刪除 操作以及操作后的刷新樹結構,具體實現(xiàn)代碼跟隨小編一起看看吧2021-08-08
element-ui帶輸入建議的input框踩坑(輸入建議空白以及會閃出上一次的輸入建議問題)
這篇文章主要介紹了element-ui帶輸入建議的input框踩坑(輸入建議空白以及會閃出上一次的輸入建議問題),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-01-01

