亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Vue實現web分頁組件詳解

發布時間:2020-09-12 15:29:21 來源:腳本之家 閱讀:182 作者:毛宇鵬 欄目:web開發

本文實例為大家分享了Vue實現web分頁組件的具體代碼,供大家參考,具體內容如下

效果演示

Vue實現web分頁組件詳解

源代碼

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>測試分頁 - www.maoyupeng.com</title>
 <style type="text/css">
  body{padding:0; margin: 0; broder:none; } #app {width: 500px; height: 200px; margin: 0 auto; text-align: center; background-color: #cccccc; } #mylink {color: #efefef; } .pagination{list-style: none; text-align: center; height: 50px; padding-top: 50px; } .pagination > li {float: left; margin: 0 5px; } [v-cloak] {display: none; } </style>
</head>
<body>
 <div id="app" v-cloak>
  <ul class="pagination">
   <li>
    <a v-if="currentPage == 1" >首頁</a>
    <a v-else href="javascript:;" @click="next(1)">首頁</a>
   </li>
   <li v-if="currentPage<=1"><a>上一頁</a></li>
   <li v-else><a href="javascript:;" @click="next(currentPage-1)">上一頁</a></li>


   <li v-for="item in pagingList">
    <a v-if="currentPage==item.key || sign ==item.key" >{{item.key}}</a>
    <a v-else href="javascript:;" @click="next(item.value)">{{item.key}}</a>
   </li>

   <li v-if="currentPage>=totalPageCount"><a>下一頁</a></li>
   <li v-else><a href="javascript:;" @click="next(currentPage+1)">下一頁</a></li>
   <li>
    <a v-if="totalPageCount == currentPage">尾頁</a>
    <a v-else href="javascript:;" @click="next(totalPageCount)">尾頁</a>
   </li>
  </ul>
  <p>共:{{totalPageCount||0}}頁,當前頁為第{{currentPage||0}}頁&nbsp;&nbsp;&nbsp;設置總頁數:<input  v-model="totalPageCount"></p>
  <a  target="_blank" id="mylink">http://www.maoyupeng.com 帶注解版本</a>
 </div>

 <script src="https://unpkg.com/vue/dist/vue.js"></script>
 <script type="text/javascript">
  var app = new Vue({
   el: '#app',
   data: {
   // 省略的符號
   sign:'...',
   // 省略號位置
   signIndex:4,
   // 總頁數
   totalPageCount: 4,
   // 當前頁
   currentPage:1,
   // 顯示在頁面的數組列表
   pagingList:[]
   },
   watch: {
   totalPageCount (val) {
    var that = this
    if (!val || val == '') return;
    that.currentPage = 1;
    that.init()
   },
   currentPage (val) {
    var that = this
    that.init()
   }
   },
   methods: {
   // 跳轉到某頁碼
   next (num) {
    var that = this
    if (num <= 1) that.currentPage = 1;
    else if (num >= that.totalPageCount) that.currentPage = that.totalPageCount;
    else that.currentPage = num;
   },
   // 初始化數據
   fetchData () {
    var that = this

    that.pagingList = [];
    var tmp = null;


    if ((that.totalPageCount) > 6) {
     if (((that.totalPageCount-1) == (that.totalPageCount - that.currentPage)) && (that.totalPageCount - that.currentPage) > 5) {
      for (var i=1;i<7;i++) {
       if (i < that.signIndex) {
        tmp = {key:i, value:i }
       } else if (i== that.signIndex) {
        tmp = {key:that.sign, value:0 }
       } else if (i == (that.signIndex + 1) ) {
        tmp = {key:that.totalPageCount - 1, value:that.totalPageCount - 1 }
       } else {
        tmp = {key:that.totalPageCount, value:that.totalPageCount }
       }
       that.pagingList.push(tmp)
      }
     } else if (((that.totalPageCount - that.currentPage) <= that.signIndex)){
      var starNum = that.totalPageCount - 5;
      for (var i=starNum;i<starNum+6;i++) {
       tmp = {key:i, value:i }
       that.pagingList.push(tmp)
      }
     } else {
      var starNum = that.currentPage - 1;
      for (var i=1;i<7;i++) {
       if (i < that.signIndex) {
        tmp = {key:(starNum - 1) + i, value:(starNum - 1) + i }
       } else if (i== that.signIndex) {
        tmp = {key:that.sign, value:0 }
       } else if (i == (that.signIndex + 1) ) {
        tmp = {key:that.totalPageCount - 1, value:that.totalPageCount - 1 }
       } else {
        tmp = {key:that.totalPageCount, value:that.totalPageCount }
       }
       that.pagingList.push(tmp)
      }
     }
    } else {
     for (var i =0; i <that.totalPageCount; i++) {
      tmp = {key:i+1, value:i+1 }
      that.pagingList.push(tmp)
     }
    }
   },
   init () {
    var that = this

    that.fetchData()
   }
   },
   mounted () {
   var that = this

   that.init()
   }
  }) 
 </script>
</body>
</html>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

额尔古纳市| 景谷| 兴和县| 莱州市| 巫山县| 佛山市| 泸定县| 获嘉县| 嵊泗县| 漳浦县| 德惠市| 师宗县| 铁力市| 明光市| 左云县| 无为县| 枝江市| 新兴县| 丹巴县| 五家渠市| 乐清市| 长岛县| 枣阳市| 蒙山县| 曲水县| 德阳市| 连江县| 天台县| 金秀| 扎囊县| 明溪县| 阿拉善盟| 庆城县| 荆门市| 杭锦后旗| 三都| 沾化县| 酉阳| 灵石县| 当涂县| 吉隆县|