国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

基于vue.js實現的分頁

2019-11-19 14:10:56
字體:
來源:轉載
供稿:網友

本文主要介紹基于vue的分頁原生寫法。

先po上效果圖:

這里寫圖片描述

html部分,將page作為一個單獨的組件

<script type="text/x-template" id="page">  <ul class="pagination">   <li v-show="current != 1" @click="current-- && goto(current)">    <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >上一頁</a>   </li>   <li v-for="index in pages" @click="goto(index)" :class="{'active':current == index}" :key="index">    <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{index}}</a>   </li>   <li v-show="allpage != current && allpage != 0 " @click="current++ && goto(current++)">    <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >下一頁</a>   </li>  </ul> </script> <div id="app">  <page></page> </div>

js部分:

 <script>  Vue.component("page", {   template: "#page",   data: function () {    return {     current: 1, // 當前頁碼     showItem: 5, // 最少顯示5個頁碼     allpage: 13 // 總共的    }   },   computed: {    pages: function () {     var pag = [];     if (this.current < this.showItem) { //如果當前的激活的項 小于要顯示的條數      //總頁數和要顯示的條數那個大就顯示多少條      var i = Math.min(this.showItem, this.allpage);      while (i) {       pag.unshift(i--);      }     } else { //當前頁數大于顯示頁數了      var middle = this.current - Math.floor(this.showItem / 2), //從哪里開始       i = this.showItem;      if (middle > (this.allpage - this.showItem)) {       middle = (this.allpage - this.showItem) + 1      }      while (i--) {       pag.push(middle++);      }     }     return pag    }   },   methods: {    goto: function (index) {     if (index == this.current) return;     this.current = index;     //這里可以發送ajax請求    }   }  })  var vm = new Vue({   el: '#app',  }) </script>

css部分:

 body {   font-family: "Segoe UI";  }  li {   list-style: none;  }  a {   text-decoration: none;  }  .pagination {   position: relative;  }  .pagination li {   display: inline-block;   margin: 0 5px;  }  .pagination li a {   padding: .5rem 1rem;   display: inline-block;   border: 1px solid #ddd;   background: #fff;   color: #0E90D2;  }  .pagination li a:hover {   background: #eee;  }  .pagination li.active a {   background: #0E90D2;   color: #fff;  }

最后附上github地址:https://github.com/AmberWuWu/vue-page

總結

以上所述是小編給大家介紹的基于vue.js實現的分頁,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 钟山县| 内乡县| 剑河县| 响水县| 岱山县| 福安市| 大英县| 武乡县| 六盘水市| 郑州市| 通渭县| 尼勒克县| 台安县| 海阳市| 安福县| 交口县| 张家界市| 西藏| 镇巴县| 镇赉县| 南召县| 清河县| 泗水县| 施秉县| 哈巴河县| 襄垣县| 红安县| 长泰县| 巴青县| 芦山县| 罗江县| 长宁县| 临桂县| 广元市| 西乌珠穆沁旗| 海城市| 苏尼特右旗| 临洮县| 延长县| 塘沽区| 隆子县|