Bootstrap4與Vue2實作分頁查詢功能(附程式碼)
這次帶給大家Bootstrap4與Vue2實作分頁查詢功能(附程式碼),Bootstrap4與Vue2實作分頁查詢功能的注意事項有哪些,以下就是實戰案例,一起來看一下。
寫在前面
# 工程為前後端分離設計,使用Nginx為前端資源伺服器,同時實作後台服務的反向代理。後台為Java Web工程,使用Tomcat部署服務。
前端框架:Bootstrap4,Vue.js2
-
後台框架:spring boot,spring data JPA
- ## 開發工具: IntelliJ IDEA,Maven
一、使用Bootstrap建構表格
表格區<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>
<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>
二、初始化Vue物件及資料
# 建立Vue物件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); } } });
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> 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>
三、使用JPA實作分頁查詢
controller接收請求/** * 用户相关请求控制器 * @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); } }
@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); } }
以上是Bootstrap4與Vue2實作分頁查詢功能(附程式碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

vue2與vue3中生命週期執行順序區別生命週期比較vue2中執行順序beforeCreate=>created=>beforeMount=>mounted=>beforeUpdate=>updated=>beforeDestroy=>destroyedvue3中執行順序setup=>onBefore>beforeDestroy=>destroyedvue3中執行順序setup=>onBefore>beforeDestroy=>destroyedvue3中執行順序setup=>onBefore> onBeforeUpdate=>onUpdated=>onBeforeUnmount=&g

隨著網路的快速發展,IP位址成為了網路通訊中不可或缺的一環。在進行網路安全監測、流量管理、電商廣告定向投放等方面,IP位址的資訊非常重要。因此,為了方便用戶查詢IP位址/網域信息,許多網站提供了IP位址查詢功能。本篇文章將介紹如何用PHP實作IP位址查詢功能,供讀者參考。一、何為IP位址? IP位址(InternetProtocolAddress)即網路協

diff演算法是一種透過同層的樹節點進行比較的高效演算法,避免了對樹進行逐層搜尋遍歷。那麼大家對diff演算法嗎有多少了解呢?以下這篇文章就來帶大家深入解析下vue2的diff演算法,希望對大家有幫助!

教學:Java開發高德地圖地理圍籬警報資料查詢功能的實作步驟引言:高德地圖是一款功能強大的地理資訊服務平台,提供了豐富的地圖資料和服務,包括地理圍籬功能。地理圍籬是一種根據地理座標系範圍進行約束的功能,可以實現地理、區域等範圍的監控和警報。在本教學中,我們將介紹如何使用Java開發高德地圖地理圍籬警報資料查詢功能,並提供對應的程式碼範例。步驟1:申請高德地圖開

PHP開發技巧:實現資料表關聯和查詢功能在PHP開發中,經常需要處理資料庫相關的操作,其中包括資料表之間的關聯和查詢。本文將介紹如何利用PHP來實現資料表的關聯和查詢功能,並提供具體的程式碼範例。一、資料表關聯的概念資料表關聯是指透過某種規則將兩個或多個資料表中的記錄進行連接,以取得關聯表的資料資訊。常見的資料表關聯方式包括一對一關聯、一對多關聯和多對多關聯。一

如何利用PHP開發一個簡單的即時天氣查詢功能前言:隨著科技的不斷發展,人們對天氣的關注也越來越多。因此,開發一個即時天氣查詢功能的網站或應用程式成為了非常熱門的需求。本文以PHP作為開發語言,介紹如何利用PHP開發簡單的即時天氣查詢功能,並提供具體的程式碼範例。一、取得天氣資料要實現天氣查詢功能,首先需要取得即時天氣資料。目前市面上有許多天氣API供開

如何利用PHP開發一個簡單的IP位址查詢功能在網路中,IP位址是唯一標識一個設備的數位位址。有時候我們需要取得一個IP位址的相關信息,例如所屬地理位置、ISP供應商等。在本文中,我們將使用PHP來發展一個簡單的IP位址查詢功能。實現這個功能需要藉助第三方的IP位址查詢服務API,透過向該API發送HTTP請求,取得IP位址的相關資訊。以下是具體的步驟和程式碼示
