Home Web Front-end JS Tutorial Bootstrap4 and Vue2 implement paging query function (code attached)

Bootstrap4 and Vue2 implement paging query function (code attached)

Apr 14, 2018 am 10:37 AM
vue2 Query function

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.

  1. Front-end framework: Bootstrap4, Vue.js2

  2. Backend framework: spring boot, spring data JPA

  3. 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>
Copy after login

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>
Copy after login

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);
   }
  }
 });
Copy after login

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);
  }
 });
 }
Copy after login

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:&quot;/user/&quot;+pageNow,
  success:function (datas) {
  vueApp.userList = datas.content;
  vueApp.totalPages = datas.totalPages;
  vueApp.pageNow = pageNow;
  },
  error:function (res) {
  console.log(res);
  }
 });
 }
</script>
Copy after login

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);
 }
}
Copy after login

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);
 }
}
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between the life cycle execution order in vue2 and vue3 What is the difference between the life cycle execution order in vue2 and vue3 May 16, 2023 pm 09:40 PM

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

PHP implements IP address query function PHP implements IP address query function Jun 22, 2023 pm 11:22 PM

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

Quickly understand the Vue2 diff algorithm (detailed graphic explanation) Quickly understand the Vue2 diff algorithm (detailed graphic explanation) Mar 17, 2023 pm 08:23 PM

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: Implementation steps for Java development of Geographic Fence alarm data query function on Amap Tutorial: Implementation steps for Java development of Geographic Fence alarm data query function on Amap Jul 29, 2023 pm 06:45 PM

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: How to implement data table association and query functions PHP development skills: How to implement data table association and query functions Sep 20, 2023 pm 04:28 PM

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 How to use PHP to develop a simple real-time weather query function Sep 24, 2023 pm 12:03 PM

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

Let's talk about how to set up the 404 interface in Vue2 and Vue3 Let's talk about how to set up the 404 interface in Vue2 and Vue3 Feb 17, 2023 pm 02:25 PM

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 How to use PHP to develop a simple IP address query function Sep 25, 2023 am 09:52 AM

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

See all articles