亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

使用Bootstrap4 + Vue2實(shí)現(xiàn)分頁(yè)查詢的示例代碼

 更新時(shí)間:2017年12月21日 08:32:39   作者:louie孫  
本篇文章主要介紹了使用Bootstrap4 + Vue2實(shí)現(xiàn)分頁(yè)查詢的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

寫在前面

工程為前后端分離設(shè)計(jì),使用Nginx為前端資源服務(wù)器,同時(shí)實(shí)現(xiàn)后臺(tái)服務(wù)的反向代理。后臺(tái)為Java Web工程,使用Tomcat部署服務(wù)。

  1. 前端框架:Bootstrap4,Vue.js2
  2. 后臺(tái)框架:spring boot,spring data JPA
  3. 開發(fā)工具:IntelliJ IDEA,Maven

實(shí)現(xiàn)效果:

會(huì)員信息

如何使用Bootstrap+Vue來(lái)實(shí)現(xiàn)動(dòng)態(tài)table,數(shù)據(jù)的新增刪除等操作,請(qǐng)查看使用Bootstrap + Vue.js實(shí)現(xiàn)表格的動(dòng)態(tài)展示、新增和刪除 。交代完畢,本文主題開始。

一、使用Bootstrap搭建表格

表格區(qū)

<div class="row">
   <table class="table table-hover table-striped table-bordered table-sm">
    <thead class="">
    <tr>
     <th><input type="checkbox"></th>
     <th>序號(hào)</th>
     <th>會(huì)員號(hào)</th>
     <th>姓名</th>
     <th>手機(jī)號(hào)</th>
     <th>辦公電話</th>
     <th>郵箱地址</th>
     <th>狀態(tài)</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>
  </div>

分頁(yè)區(qū)

<div 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>
  </div>

二、初始化Vue對(duì)象及數(shù)據(jù)

創(chuàng)建Vue對(duì)象

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);
   }
  }
 });

初始化數(shù)據(jù)

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);
  }
 });
 }

完整js代碼:

<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實(shí)現(xiàn)分頁(yè)查詢

controller接收請(qǐng)求

/**
 * 用戶相關(guān)請(qǐng)求控制器
 * @author louie
 * @date 2017-12-19
 */
@RestController
@RequestMapping("/user")
public class UserController {

 @Autowired
 private UserService userService;

 /**
 * 分頁(yè)獲取用戶
 * @param pageNow 當(dāng)前頁(yè)碼
 * @return 分頁(yè)用戶數(shù)據(jù)
 */
 @RequestMapping("/{pageNow}")
 public Page<User> findByPage(@PathVariable Integer pageNow){
 return userService.findUserPaging(pageNow);
 }
}

JPA分頁(yè)查詢

@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);
 }
}

好了,至此功能完成,工程代碼已在GitHub中分享,您可以 點(diǎn)擊查看或下載 ,擁抱開源,共享讓世界更美好。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue.Js中的$watch()方法總結(jié)

    Vue.Js中的$watch()方法總結(jié)

    這篇文章主要給大家介紹了在Vue.Js中的$watch()方法的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來(lái)一起看看吧。
    2017-03-03
  • vue刷新后瞬間閃爍,無(wú)法解析的問題

    vue刷新后瞬間閃爍,無(wú)法解析的問題

    這篇文章主要介紹了vue刷新后瞬間閃爍,無(wú)法解析的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • vue 實(shí)現(xiàn)click同時(shí)傳入事件對(duì)象和自定義參數(shù)

    vue 實(shí)現(xiàn)click同時(shí)傳入事件對(duì)象和自定義參數(shù)

    這篇文章主要介紹了vue 實(shí)現(xiàn)click同時(shí)傳入事件對(duì)象和自定義參數(shù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-01-01
  • Vue2.0表單校驗(yàn)組件vee-validate的使用詳解

    Vue2.0表單校驗(yàn)組件vee-validate的使用詳解

    本篇文章主要介紹了Vue2.0表單校驗(yàn)組件vee-validate的使用詳解,詳細(xì)的介紹了vee-validate使用教程。具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • 在vue-cli項(xiàng)目中如何使用swiper

    在vue-cli項(xiàng)目中如何使用swiper

    這篇文章主要介紹了在vue-cli項(xiàng)目中如何使用swiper問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • vue3.0透?jìng)鲗傩院褪录氖褂梅绞脚e例

    vue3.0透?jìng)鲗傩院褪录氖褂梅绞脚e例

    這篇文章主要給大家介紹了關(guān)于vue3.0透?jìng)鲗傩院褪录褂玫南嚓P(guān)資料,透?jìng)鱝ttribute指的是傳遞給一個(gè)組件,卻沒有被該組件聲明為props或emits的attribute或者v-on事件監(jiān)聽器,需要的朋友可以參考下
    2024-01-01
  • vue+django實(shí)現(xiàn)一對(duì)一聊天功能的實(shí)例代碼

    vue+django實(shí)現(xiàn)一對(duì)一聊天功能的實(shí)例代碼

    這篇文章主要介紹了vue+django實(shí)現(xiàn)一對(duì)一聊天功能,主要是通過(guò)websocket,由于Django不支持websocket,所以我使用了django-channels。,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2019-07-07
  • Vue+Element?switch組件的使用示例代碼詳解

    Vue+Element?switch組件的使用示例代碼詳解

    這篇文章主要介紹了Vue+Element?switch組件的使用,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-06-06
  • Vue滑塊解鎖組件使用方法詳解

    Vue滑塊解鎖組件使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了Vue滑塊解鎖組件的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • vue移動(dòng)端項(xiàng)目渲染pdf步驟及問題小結(jié)

    vue移動(dòng)端項(xiàng)目渲染pdf步驟及問題小結(jié)

    這篇文章主要介紹了vue移動(dòng)端項(xiàng)目渲染pdf步驟,vue-pdf的插件在使用的過(guò)程中是連連踩坑的,基本遇到3個(gè)問題,分別在文中給大家詳細(xì)介紹,需要的朋友可以參考下
    2022-08-08

最新評(píng)論