欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Vue實(shí)現(xiàn)簡(jiǎn)單分頁器

提前說明:這原本是一個(gè)Jquery分頁器,因?yàn)楣卷?xiàng)目前后端不分離,以前的分頁用的是基于.net的分頁器。后來我引入了jquery分頁器,在我掌握Vue之后,又自己寫了一些基于Vue的插件(為什么不用成熟的Vue插件庫(kù),還是因?yàn)榍昂蠖藳]分離)但是前后端相對(duì)最開始的混雜已經(jīng)算是分得很開了。

創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括加格達(dá)奇網(wǎng)站建設(shè)、加格達(dá)奇網(wǎng)站制作、加格達(dá)奇網(wǎng)頁制作以及加格達(dá)奇網(wǎng)絡(luò)營(yíng)銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,加格達(dá)奇網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到加格達(dá)奇省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

分頁器的樣式是bootstrap風(fēng)格的,是一個(gè)完全自定義樣式的分頁器,這意味著你可以很輕松把它改成你想要的樣子(例子效果圖如下)。

Vue實(shí)現(xiàn)簡(jiǎn)單分頁器

所有的分頁器DEMO,都不會(huì)太簡(jiǎn)單,所以想要真正的掌握(支配)一款好用的分頁插件,請(qǐng)務(wù)必耐心看下面的使用示例代碼(本demo的下載地址,點(diǎn)擊可以作為項(xiàng)目直接打開使用),另外也寫了詳細(xì)的注釋并盡可能的保證簡(jiǎn)單好用。
引用bootstrap(如果你希望是bootstrap風(fēng)格)
或者你完全可以自己寫自己想要的風(fēng)格!因?yàn)榉猪撈鞯膆tml結(jié)構(gòu)是js生成的。
需要引用的腳本文件有(資源均在文章底部下載包里)。

按如下順序引入:

1.jQuery
2.Vue
3.jgPaginator.js

貼代碼,看注釋:

<!DOCTYPE html>
<html>

 <head>
  <meta charset="UTF-8">
  <title>分頁組件</title>
  <link rel="stylesheet" href="../../css/bootstrap.min.css" >

  <style>
   html,
   body {
    width: 100%;
    height: 100%;
   }

   .page-container {
    width: 1200px;
    border: 1px solid #000;
    margin: 50px auto 0 auto;
    overflow: hidden;
   }

   .page-content{
    margin: 50px 0;
   }

   /*jqPaginator分頁控件樣式*/ 
   .hiddenPager {
    visibility: hidden;
   }

   .jqPager {
    position: relative;
    width: 100%;
    height: 40px;
    padding: 25px 0;
    background-color: #FFF;
   }

   .jqPager .pagination {
    float: initial;
    display: inline-block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    margin: 0 auto;
    text-align: center;
   }

   .jqPager .pagination li {
    display: inline-block;
   }

   .jqPager .pagination li a {
    padding: 4px 10px;
   }

   /*跳頁--選用功能*/
   .jumpBox {
    position: absolute;
    top: 0;
    right: 105px;
   }

   .jumppage {
    display: block;
    width: 42px;
    padding-left: 8px;
    float: left;
    height: 34px;
    outline: none;
   }

   .jumpbtn {
    float: left;
    display: block;
    height: 34px;
    line-height: 34px;
    margin-left: 5px;
   }
  </style>

 </head>

 <body>

  <div id="app" class="page-container">
   <!--頁面該顯示的內(nèi)容-->
   <div class="page-content text-center">{{nova.text}}</div>

   <!--分頁-->
   <div class="jqPager" v-bind:class="{hiddenPager:hiddenPager}">
    <ul id="jqPager" class="pagination cf"></ul>
    <!--沒有跳頁功能可以不要下面的jumpBox-->
    <div class="jumpBox">
     <input type="number" class="jumppage" id="jumpPageIndex" />
     <a href="javascript:;" rel="external nofollow" class="jumpbtn" v-on:click="pageSkip()">跳轉(zhuǎn)</a>
    </div>
   </div>

  </div>

 </body>
 <script src="jquery-2.1.4.min.js"></script>
 <script src="vue.js"></script>
 <script src="jqPaginator.js"></script>
 <script>
  //虛擬的數(shù)據(jù)來源
  var dataSource = [{
    "text": "第一頁數(shù)據(jù),應(yīng)該是一個(gè)數(shù)組,包含了pageSize條數(shù)據(jù)"
   }, {
    "text": "第二頁數(shù)據(jù)"
   }, {
    "text": "第三頁數(shù)據(jù)"
   },
   {
    "text": "第四頁數(shù)據(jù)"
   },
   {
    "text": "第五頁數(shù)據(jù)"
   },
   {
    "text": "第六頁數(shù)據(jù)"
   }
  ]

  //模擬后臺(tái)返回的數(shù)據(jù)
  var backData = {
   Data: dataSource,//返回的數(shù)據(jù)
   totlaCount: 6,//搜索結(jié)果總數(shù)
   Success: true//請(qǐng)求接口是否成功
  };

  /*每一頁顯示的數(shù)據(jù)條數(shù),按照約定傳給后臺(tái),此例為1。
  需要加以說明的是這個(gè)實(shí)例你是看不出來這個(gè)參數(shù)的作用的,正如我返回?cái)?shù)據(jù)中說的那樣,后臺(tái)給你返回的數(shù)據(jù)條數(shù)
  應(yīng)該是一個(gè)有 -pagesize-條數(shù)據(jù)的數(shù)組才對(duì)*/
  var jqPageSize = 1; 

  var app = new Vue({
   el: "#app",
   data: {
    //query是查詢條件,這里就是當(dāng)前頁碼和每一頁該顯示的數(shù)據(jù)條數(shù)
    query: {
     pageIndex: 1,
     pageSize: jqPageSize
    },
    nova: [],
    hiddenPager: true,//是否顯示分頁
    totalCount: 0,//數(shù)據(jù)總條數(shù),后臺(tái)返回
   },
   methods: {
    //初始化分頁,通過更改生成的html結(jié)構(gòu)(給其添加class或者改變返回的DOM)可以手動(dòng)配置頁器的顯示效果。
    initPager: function() {
     $('#jqPager').jqPaginator({
      visiblePages: 1,
      currentPage: 1,
      totalPages: 1,
      first: '<li id="first"><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁</a></li>',
      prev: '<li id="prev"><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >上一頁 </a></li>',
      next: '<li id="next"><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >下一頁</a></li>',
      last: '<li id="last"><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >尾頁</a></li>',
      page: '<li class="page"><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{page}}</a></li>',
     });
    },

    //獲取數(shù)據(jù)并根據(jù)結(jié)果配置分頁
    getData: function() {
     this.nova = backData.Data[this.query.pageIndex - 1];     
     this.totalCount = backData.Data.length;
     this.hiddenPager = false;

     //核心配置在此部,根據(jù)后臺(tái)返回?cái)?shù)據(jù)控制分頁器該如何顯示
     //想要完全掌握這個(gè)分頁器,你可以研究下jgPaginator.js源碼,很容易修改。
     $('#jqPager').jqPaginator('option', {
      totalCounts: app.totalCount,//后臺(tái)返回?cái)?shù)據(jù)總數(shù)
      pageSize: jqPageSize, //每一頁顯示多少條內(nèi)容
      currentPage: app.query.pageIndex, //現(xiàn)在的頁碼
      visiblePages: 4, //最多顯示幾頁

      //翻頁時(shí)觸發(fā)的事件
      onPageChange: function(num) {
       //app.query.pageIndex = num;
       app.pageChangeEvent(num);//調(diào)用翻頁事件
      }
     });
    },
    //翻頁或者跳頁事件
    pageChangeEvent: function(pageIndex) {
     this.query.pageIndex = Number(pageIndex);
     this.getData();
    },

    //跳頁-選用功能,可有可無
    pageSkip: function() {  
     var maxPage = 1;//默認(rèn)可以跳的最大頁碼     
     var targetPage = document.getElementById("jumpPageIndex").value;//目的頁面     
     if(!targetPage) {
      alert("請(qǐng)輸入頁碼");
      return;
     }

     //計(jì)算最大可跳頁數(shù)
     maxPage = Math.floor(this.totalCount / this.query.pageSize);     
     if(maxPage<1){
      maxPage=1;
     }

     if(targetPage > maxPage) {
      alert('超過最大頁數(shù)了,當(dāng)前最大頁數(shù)是' + maxPage);
      return;
     }
     this.pageChangeEvent(targetPage);
    },   
   },
   //這一部分的定時(shí)器是為了此例方便加上的,初始化分頁方法(initPager)要在獲取數(shù)據(jù)之前執(zhí)行就可以了
   mounted: function() {
    this.initPager();

    setTimeout(function() {
     app.getData();
    }, 50)
   }

  });
 </script>

</html>

以上就是分頁的全部實(shí)現(xiàn)代碼,想要完全掌握,只看DEMO肯定是不夠的,所以這里是DEMO的下載地址,里面包含了所有需要引用的資源文件以及未壓縮的分頁器核心:jqPaginator.js。你需要好好看看它的源碼!

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

網(wǎng)頁名稱:Vue實(shí)現(xiàn)簡(jiǎn)單分頁器
分享路徑:http://www.chinadenli.net/article34/jdjese.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司網(wǎng)站收錄響應(yīng)式網(wǎng)站定制開發(fā)云服務(wù)器品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)