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
Table of contents Common array methods Adding and...
1. Composition and related concepts of MySQL data...
Table of contents 1. switch 2. While Loop 3. Do/W...
Table of contents Why use Docker? Docker installa...
This article shares the specific code of the appl...
background When you open the product details on s...
mysql5.5.28 installation tutorial for your refere...
Table of contents 1. Use scripts to encrypt TLS f...
1. Search mysql in the browser to download and in...
Table of contents Overview Problem Description Ci...
Table of contents Bubble Sort Selection Sort Inse...
Referring to other more professional blog systems...
1. Set the list symbol list-style-type: attribute...
use <div id="app"> <router-lin...
In the process of making web pages, we often use f...