Vue implements paging function

Vue implements paging function

This article example shares the specific code of Vue to implement the paging function for your reference. The specific content is as follows

  • Using component paging
  • Write your own pagination

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 paging

Sometimes 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 display

computed: {
      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 pages

Method 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:
  • Vue form form submission + ajax asynchronous request + paging effect
  • Vue.js implements paging query function
  • Example code for writing a pager with Vue
  • Vue.js realizes infinite loading and paging function development
  • Vue.js table paging example
  • VUE+SpringBoot implements paging function
  • Vue component library ElementUI realizes the paging effect of table list
  • How to use ElementUI pagination component Pagination in Vue
  • Vue project realizes paging effect
  • Vue+iview realizes paging and query functions
  • Encapsulation of vue+iview paging component

<<:  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

Recommend

Analysis of two usages of the a tag in HTML post request

Two examples of the use of the a tag in HTML post...

How to quickly build an FTP file service using FileZilla

In order to facilitate the storage and access of ...

How to get the size of a Linux system directory using the du command

Anyone who has used the Linux system should know ...

Detailed implementation plan of Vue front-end exporting Excel files

Table of contents 1. Technology Selection 2. Tech...

Nginx improves access speed based on gzip compression

1. Why does nginx use gzip? 1. The role of compre...

Introduction to useRef and useState in JavaScript

Table of contents 1. useState hook 2. useRef hook...

How to build Jenkins+Maven+Git continuous integration environment on CentOS7

This article takes the deployment of Spring boot ...

WeChat Mini Program Basic Tutorial: Use of Echart

Preface Let’s take a look at the final effect fir...

An example of installing MySQL on Linux and configuring external network access

Configuration steps 1. Check whether DNS is confi...

Vue parent-child component mutual value transfer and call

Table of contents 1. Parent passes value to child...

FlashFXP ftp client software registration cracking method

The download address of FlashFXP is: https://www....

The whole process record of vue3 recursive component encapsulation

Table of contents Preface 1. Recursive components...