Bootstrap4 and Vue2 implement paging query function (code attached)
This time I will bring you Bootstrap4 and Vue2 to implement the paging query function (with code), what are the precautions for Bootstrap4 and Vue2 to implement the paging query function, the following is the actual combat Let’s take a look at the case.
Write in front
The project is designed to separate the front and back ends, using Nginx as the front-end resource server, and at the same time realizing the reverse proxy of the back-end service. The background is a Java Web project, using Tomcat to deploy services.
Front-end framework: Bootstrap4, Vue.js2
-
Backend framework: spring boot, spring data JPA
Development tools: IntelliJ IDEA, Maven
How to use Bootstrap Vue to implement dynamic table, data addition and deletion and other operations, please check out Using Bootstrap Vue.js to implement dynamic display, addition and deletion of tables. After the explanation is completed, the topic of this article begins.
1. Use Bootstrap to build a table
Table area
<p class="row"> <table class="table table-hover table-striped table-bordered table-sm"> <thead class=""> <tr> <th><input type="checkbox"></th> <th>序号</th> <th>会员号</th> <th>姓名</th> <th>手机号</th> <th>办公电话</th> <th>邮箱地址</th> <th>状态</th> </tr> </thead> <tbody> <tr v-for="(user,index) in userList"> <td><input type="checkbox" :value="index" v-model="checkedRows"></td> <td>{{pageNow*10 + index+1}}</td> <td>{{user.id}}</td> <td>{{user.username}}</td> <td>{{user.mobile}}</td> <td>{{user.officetel}}</td> <td>{{user.email}}</td> <td v-if="user.disenable == 0">正常</td> <td v-else>注销</td> </tr> </tbody> </table> </p>
Paging area
<p class="row mx-auto"> <ul class="nav justify-content-center pagination-sm"> <li class="page-item"> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="page-link"><i class="fa fa-fast-backward" @click="switchToPage(0)"> </i></a> </li> <li class="page-item"> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="page-link"><i class="fa fa-backward" @click="switchToPage(pageNow-1)"></i></a> </li> <li class="page-item" v-for="n in totalPages" :class="{active:n==pageNow+1}"> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" @click="switchToPage(n-1)" class="page-link">{{n}}</a> </li> <li class="page-item"> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="page-link"><i class="fa fa-forward" @click="switchToPage(pageNow+1)"></i></a> </li> <li class="page-item"> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="page-link"><i class="fa fa-fast-forward" @click="switchToPage(totalPages-1)"></i></a> </li> </ul> </p>
2. Initialize VueObject and data
Create Vue object
var vueApp = new Vue({ el:"#vueApp", data:{ userList:[], perPage:10, pageNow:0, totalPages:0, checkedRows:[] }, methods:{ switchToPage:function (pageNo) { if (pageNo < 0 || pageNo >= this.totalPages){ return false; } getUserByPage(pageNo); } } });
Initialization data
function getUserByPage(pageNow) { $.ajax({ url:"/user/"+pageNow, success:function (datas) { vueApp.userList = datas.content; vueApp.totalPages = datas.totalPages; vueApp.pageNow = pageNow; }, error:function (res) { console.log(res); } }); }
Complete js code:
<script> var vueApp = new Vue({ el:"#vueApp", data:{ userList:[], perPage:10, pageNow:0, totalPages:0, checkedRows:[] }, methods:{ switchToPage:function (pageNo) { if (pageNo < 0 || pageNo >= this.totalPages){ return false; } getUserByPage(pageNo); } } }); getUserByPage(0); function getUserByPage(pageNow) { $.ajax({ url:"/user/"+pageNow, success:function (datas) { vueApp.userList = datas.content; vueApp.totalPages = datas.totalPages; vueApp.pageNow = pageNow; }, error:function (res) { console.log(res); } }); } </script>
3. Use JPA to implement paging query
Controller receives request
/** * 用户相关请求控制器 * @author louie * @date 2017-12-19 */ @RestController @RequestMapping("/user") public class UserController { @Autowired private UserService userService; /** * 分页获取用户 * @param pageNow 当前页码 * @return 分页用户数据 */ @RequestMapping("/{pageNow}") public Page<User> findByPage(@PathVariable Integer pageNow){ return userService.findUserPaging(pageNow); } }
JPA paging query
@Service public class UserServiceImpl implements UserService { @Value("${self.louie.per-page}") private Integer perPage; @Autowired private UserRepository userRepository; @Override public Page<User> findUserPaging(Integer pageNow) { Pageable pageable = new PageRequest(pageNow,perPage,Sort.Direction.DESC,"id"); return userRepository.findAll(pageable); } }
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
Analysis of steps for building multi-page applications with webpack
How to add a progress bar to uploaded images in axios
Where does this point when vue uses axios
The above is the detailed content of Bootstrap4 and Vue2 implement paging query function (code attached). 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

AI Hentai Generator
Generate AI Hentai for free.

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



Difference in life cycle execution order between vue2 and vue3 Life cycle comparison The execution order in vue2 beforeCreate=>created=>beforeMount=>mounted=>beforeUpdate=>updated=>beforeDestroy=>destroyed The execution order in vue3 setup=>onBeforeMount=>onMounted=> onBeforeUpdate=>onUpdated=>onBeforeUnmount=&g

With the rapid development of the Internet, IP addresses have become an indispensable part of network communications. IP address information is very important in network security monitoring, traffic management, and targeted e-commerce advertising. Therefore, in order to facilitate users to query IP address/domain name information, many websites provide IP address query functions. This article will introduce how to use PHP to implement the IP address query function for readers' reference. 1. What is an IP address? IP address (InternetProtocolAddress) is the network protocol

The diff algorithm is an efficient algorithm that compares tree nodes at the same level, avoiding the need to search and traverse the tree layer by layer. So how much do you know about the diff algorithm? The following article will give you an in-depth analysis of the diff algorithm of vue2. I hope it will be helpful to you!

Tutorial: Java development steps for implementing the geofence alarm data query function of Amap. Introduction: Amap is a powerful geographic information service platform that provides a wealth of map data and services, including geofence functions. Geofencing is a function that restricts according to the scope of the geographical coordinate system, and can realize monitoring and alarming in regions, regions, etc. In this tutorial, we will introduce how to use Java to develop the geofence alarm data query function of Amap and provide corresponding code examples. Step 1: Apply for Amap to open

PHP development skills: Implement data table association and query functions In PHP development, it is often necessary to handle database-related operations, including associations and queries between data tables. This article will introduce how to use PHP to implement the correlation and query functions of data tables, and provide specific code examples. 1. The concept of data table association Data table association refers to connecting the records in two or more data tables through certain rules to obtain the data information of the associated table. Common data table association methods include one-to-one association, one-to-many association and many-to-many association. one

How to use PHP to develop a simple real-time weather query function Preface: With the continuous development of technology, people are paying more and more attention to the weather. Therefore, developing a website or application with real-time weather query function has become a very popular demand. This article uses PHP as the development language, introduces how to use PHP to develop a simple real-time weather query function, and provides specific code examples. 1. Obtaining weather data To implement the weather query function, you first need to obtain real-time weather data. There are currently many weather APIs available on the market for development

This article will take you through Vue learning and talk about how to set up the 404 interface in Vue2 and Vue3. I hope it will be helpful to you!

How to use PHP to develop a simple IP address query function. In the network, the IP address is a numerical address that uniquely identifies a device. Sometimes we need to obtain relevant information about an IP address, such as its geographical location, ISP provider, etc. In this article, we will use PHP to develop a simple IP address query function. To implement this function, you need to use a third-party IP address query service API to obtain IP address-related information by sending an HTTP request to the API. The following are the specific steps and code examples
