This article example shares the specific code of Vue to implement the paging function for your reference. The specific content is as follows
1. Component Paging<el-pagination layout="prev, pager, next" @current-change="changePageNum" :current-page="pageNum" :page-size="pageSize" :total="total"> </el-pagination> data(){ return { tableData: [], total: 0, //Total number pageNum: 1, //Current page pageSize: 15, //Number of pages displayed per page} } mounted: function () { this.query(); //Get data when loading the page}, methods:{ //Switch page numberchangePageNum: function (val) { this.pageNum = val; this.query(); }, //Get data through the interface query: function () { var data = { name: this.name || '', fleetId: this.FleetId, pageNum: this.pageNum, //Current page pageSize: this.pageSize //Query number}; 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('Query failed'); } }).catch(err => { // Abnormal situation console.log(err); }); }, } Component paging effect 2. Build your own pagingSometimes you need to write your own paging according to your needs 1. Pagination style 2. Cut pages up and down //Scheduling - system address book paging dispatchCourentPage: 1, //Scheduling - System Address Book currently selected tag mark dispatchCourentIndex: 1, //Scheduling-system address book more mark items: group id dispatchMorecommandGroupId: '', dispatchTotlePage: 0, //Previous page handleLastPage() { if (this.dispatchCourentPage === 1) return; this.dispatchCourentPage -= 1; let index = this.dispatchCourentIndex; if (this.dispatchMorecommandGroupId != '') { this.queryBookMoreBygroupId(this.dispatchMorecommandGroupId); } else { this.queryBookmember(index); } }, //Next page 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); } } 3. Use monitoring properties to control paging displaycomputed: { limitData() { let data = [...this.table1Datas]; return data; }, // Because the total number of pages needs to be calculated dynamically, a calculated property is also required to return the final data to the Table dataWithPage() { const data = this.limitData; const start = this.current * this.size - this.size; const end = start + this.size; return [...data].slice(start, end); }, } 4. js controls paging and calculates the total number of pagesMethod 1 /** *Calculate the number of pages based on the number of data items and the number of data items per page* totalnum number of data items* limit number of data items per page*/ pageCount(totalnum, limit) { return totalnum > 0 ? ((totalnum < limit) ? 1 : ((totalnum % limit) ? (parseInt(totalnum / limit) + 1) : (totalnum / limit))) : 0; }, Method 2 /** * Total number of pages for paging* Total number of records: totalRecord * Maximum number of records per page: maxResult */ function pageCount() { totalPage = (totalRecord + maxResult -1) / maxResult; } Method 3 Recommended totalPage = Math.floor((totalRecord +maxResult -1) /maxResult ); The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of basic data types in mysql8.0.19
>>: Example of how to set up a Linux system to automatically run a script at startup
Two examples of the use of the a tag in HTML post...
In order to facilitate the storage and access of ...
Anyone who has used the Linux system should know ...
Table of contents 1. Install Docker 2. Install an...
Table of contents 1. Technology Selection 2. Tech...
1. Why does nginx use gzip? 1. The role of compre...
Table of contents 1. useState hook 2. useRef hook...
This article takes the deployment of Spring boot ...
Preface Let’s take a look at the final effect fir...
Configuration steps 1. Check whether DNS is confi...
Table of contents 1. Parent passes value to child...
First, let’s think about a question: To insert su...
The download address of FlashFXP is: https://www....
Table of contents Preface 1. Recursive components...
Use profile to analyze slow SQL The main purpose ...