


Implementing paging in vue.js by clicking the page number to replace the page content
Below I will share with you a method of clicking the page number to change the page content in vue.js paging (with spring springmvc). It has a good reference value and I hope it will be helpful to everyone.
html code:
<section class="container page-home"> <p id="main-content" class="wrap-container zerogrid"> <article id="news_content" v-for="item in items"> <p class="col-1-2 right"> <img :src="item.coverimage" class="news_image"/> <!-- :要与img标签之间有空格 --> </p> <p class="col-1-2 left"> <a class="art-category left" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{item.releasetime.substring(0,19)}}</a> <p class="clear"></p> <p class="art-content"> <h2>{{item.title}}</h2> <p class="info"> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{item.author}}</a> </p> <p class="line"></p> <p>{{item.remark}}</p> <a v-bind:href="['/island/stage/newscontent.html?id='+item.id+'&categoryid='+item.categoryid]" rel="external nofollow" class="more">阅读全文</a> <span href="javascript:;" rel="external nofollow" class="more" style="margin-left:50px;">浏览量 : {{item.reading}}</span> </p> </p> </article> <!-- 循环结束(新闻) --> </p> <p id="pagination" class="clearfix"> <ul> <li v-for="page in pages"> <a class="current" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" v-if="currentPage == page">{{page}}</a> <!-- 高亮显示当前页 --> <a class="choose_page" v-if="currentPage != page" @click="clickpage">{{page}}</a> </li> <li v-if="pages > 1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >next</a></li> </ul> </p> </section>
js:
/查询相关新闻种类下的所有新闻记录 var vm = new Vue({ el: '.page-home', //需要注入的模板的父元素 data: { items : [], pages : [], currentPage : [] }, //end data created:function(){ $.post("/island/stage/queryOneCategoryAllNews.do",{"categoryid":parseInt(categoryid),"currentPage":1},function(data){ vm.pages = data.totalPage; //总页码 vm.items = data.list; //循环内容 vm.currentPage = data.currentPage; //当前页(添加高亮样式) }); //end post }, //created methods:{ clickpage:function(event){ var currentPage = $(event.currentTarget).text(); $.post("/island/stage/queryOneCategoryAllNews.do",{"categoryid":parseInt(categoryid),"currentPage":parseInt(currentPage)},function(data){ vm.items = data.list; //循环内容 vm.pages = data.totalPage; //总页码 vm.currentPage = data.currentPage; //当前页(添加高亮样式) }); //end post } //end method } }); //end vue
javaBackend:
package com.zrq.util; import java.util.List; import org.springframework.stereotype.Component; @Component public class PageUtil { /* * // 默认的每页记录数量(10条) private static final int DEFAULT_PAGE_SIZE = 10; // * 默认当前页 private static final int DEFAULT_CURRENT_PAGE = 1; */ // 1.每页显示数量(everyPage) private int everyPage; // 2.总记录数(totalCount) private long totalCount; // 3.总页数 private long totalPage; // 4.当前页(currentPage) private int currentPage; // 5.起始下标(beginIndex) private int beginIndex; // 6.判断是否有上一页 private boolean next; // 7.判断是否有下一页 private boolean previous; // 8.返回列表 private List list; /* 获取总页数 */ public long getTotalPage() { long remainder = totalCount % this.getEveryPage(); // 剩余数 if (remainder == 0) totalPage = totalCount / this.getEveryPage(); else totalPage = totalCount / this.getEveryPage() + 1; return totalPage; } /* 判断是否有上一页 */ public void hasPrevious() { if (currentPage > 1) this.setPrevious(true); else this.setPrevious(false); } /* 判断是否有下一页 */ public void hasNext() { if (currentPage < this.getTotalCount()) this.setNext(true); else this.setNext(false); } public boolean isNext() { return next; } public boolean isPrevious() { return previous; } public void setTotalPage(long totalPage) { this.totalPage = totalPage; } public void setNext(boolean next) { this.next = next; } public void setPrevious(boolean previous) { this.previous = previous; } public int getEveryPage() { return everyPage; } public long getTotalCount() { return totalCount; } public int getCurrentPage() { return currentPage; } public int getBeginIndex() { return beginIndex; } public List getList() { return list; } public void setEveryPage(int everyPage) { this.everyPage = everyPage; } public void setTotalCount(long totalCount) { this.totalCount = totalCount; } public void setCurrentPage(int currentPage) { this.currentPage = currentPage; } public void setBeginIndex(int beginIndex) { this.beginIndex = beginIndex; } public void setList(List list) { this.list = list; } public PageUtil(int currentPage, int pageSize) { this.currentPage = currentPage; this.everyPage = pageSize; } public PageUtil() { /* * this.currentPage = DEFAULT_CURRENT_PAGE; this.everyPage = * DEFAULT_PAGE_SIZE; */ } public PageUtil(int everyPage, int totalCount, int currentPage, int beginIndex, List list) { super(); this.everyPage = everyPage; this.totalCount = totalCount; this.currentPage = currentPage; this.beginIndex = beginIndex; this.list = list; } }
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Using Elememt-UI to build the management backend in Vue (detailed tutorial)
Through WebView in react-native Handle return non-callback method
Method of reading data through json file in Vue2.5
The above is the detailed content of Implementing paging in vue.js by clicking the page number to replace the page content. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In 2023, AI technology has become a hot topic and has a huge impact on various industries, especially in the programming field. People are increasingly aware of the importance of AI technology, and the Spring community is no exception. With the continuous advancement of GenAI (General Artificial Intelligence) technology, it has become crucial and urgent to simplify the creation of applications with AI functions. Against this background, "SpringAI" emerged, aiming to simplify the process of developing AI functional applications, making it simple and intuitive and avoiding unnecessary complexity. Through "SpringAI", developers can more easily build applications with AI functions, making them easier to use and operate.

As an industry leader, Spring+AI provides leading solutions for various industries through its powerful, flexible API and advanced functions. In this topic, we will delve into the application examples of Spring+AI in various fields. Each case will show how Spring+AI meets specific needs, achieves goals, and extends these LESSONSLEARNED to a wider range of applications. I hope this topic can inspire you to understand and utilize the infinite possibilities of Spring+AI more deeply. The Spring framework has a history of more than 20 years in the field of software development, and it has been 10 years since the Spring Boot 1.0 version was released. Now, no one can dispute that Spring

How to implement spring programmatic transactions: 1. Use TransactionTemplate; 2. Use TransactionCallback and TransactionCallbackWithoutResult; 3. Use Transactional annotations; 4. Use TransactionTemplate in combination with @Transactional; 5. Customize the transaction manager.

How to set the transaction isolation level in Spring: 1. Use the @Transactional annotation; 2. Set it in the Spring configuration file; 3. Use PlatformTransactionManager; 4. Set it in the Java configuration class. Detailed introduction: 1. Use the @Transactional annotation, add the @Transactional annotation to the class or method that requires transaction management, and set the isolation level in the attribute; 2. In the Spring configuration file, etc.

MyBatis is an excellent persistence layer framework. It supports database operations based on XML and annotations. It is simple and easy to use. It also provides a rich plug-in mechanism. Among them, the paging plug-in is one of the more frequently used plug-ins. This article will delve into the principles of the MyBatis paging plug-in and illustrate it with specific code examples. 1. Paging plug-in principle MyBatis itself does not provide native paging function, but you can use plug-ins to implement paging queries. The principle of paging plug-in is mainly to intercept MyBatis

Spring is an open source framework that provides many annotations to simplify and enhance Java development. This article will explain commonly used Spring annotations in detail and provide specific code examples. @Autowired: Autowired @Autowired annotation can be used to automatically wire beans in the Spring container. When we use the @Autowired annotation where dependencies are required, Spring will find matching beans in the container and automatically inject them. The sample code is as follows: @Auto

In back-end management systems, access permission control is usually required to limit different users' ability to access interfaces. If a user lacks specific permissions, he or she cannot access certain interfaces. This article will use the waynboot-mall project as an example to introduce how common back-end management systems introduce the permission control framework SpringSecurity. The outline is as follows: waynboot-mall project address: https://github.com/wayn111/waynboot-mall 1. What is SpringSecurity? SpringSecurity is an open source project based on the Spring framework, aiming to provide powerful and flexible security for Java applications.

JUnit is a widely used Java unit testing framework in Spring projects and can be applied by following steps: Add JUnit dependency: org.junit.jupiterjunit-jupiter5.8.1test Write test cases: Use @ExtendWith(SpringExtension.class) to enable extension, use @Autowired inject beans, use @BeforeEach and @AfterEach to prepare and clean, and mark test methods with @Test.
