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

JavaScript Array Methods - Systematic Summary and Detailed Explanation

Table of contents Common array methods Adding and...

Detailed explanation of MySQL database (based on Ubuntu 14.0.4 LTS 64 bit)

1. Composition and related concepts of MySQL data...

JavaScript common statements loop, judgment, string to number

Table of contents 1. switch 2. While Loop 3. Do/W...

About ROS2 installation and docker environment usage

Table of contents Why use Docker? Docker installa...

Mini Program to Implement Text Circular Scrolling Animation

This article shares the specific code of the appl...

How to encapsulate timer components in Vue3

background When you open the product details on s...

mysql5.5.28 installation tutorial is super detailed!

mysql5.5.28 installation tutorial for your refere...

How to connect to a remote docker server with a certificate

Table of contents 1. Use scripts to encrypt TLS f...

Three JavaScript methods to solve the Joseph ring problem

Table of contents Overview Problem Description Ci...

How to use JavaScript to implement sorting algorithms

Table of contents Bubble Sort Selection Sort Inse...

Add a copy code button code to the website code block pre tag

Referring to other more professional blog systems...

CSS sets the list style and creates the navigation menu implementation code

1. Set the list symbol list-style-type: attribute...

Two methods to disable form controls in HTML: readonly and disabled

In the process of making web pages, we often use f...