本文主要介绍基于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实现的分页,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 金池VS刘罡2009《双声情》[WAV+CUE]
- 冯奥迪《卄》[320K/MP3][67.08MB]
- 冯奥迪《卄》[FLAC/分轨][172.46MB]
- Merryland《Merryland》[320K/MP3][69.48MB]
- 苏芮.1991-停在我心里的温柔【福茂】【WAV+CUE】
- 苏慧伦.2020-面面Every.Side.of.Me【相信音乐】【WAV+CUE】
- 群星.1991-不一样的感觉REMIX【宝丽金】【WAV+CUE】
- 银霞.1983-《你那好冷的小手》珍藏纪念版[WAV分轨]
- 银霞.2002-《国语巨星专辑VOL.3》2CD台湾版[WAV+CUE]
- 金池刘罡《昨日情歌HQ》头版限量编号[低速原抓WAV+CUE]
- 段奥娟.2024-23·岁碎念【白米范】【FLAC分轨】
- 顺子.2001-昨日·唯一·更多·顺子自选辑【魔岩】【WAV+CUE】
- 无印良品.1999-私藏三首·原创相对论(EP)【滚石】【WAV+CUE】
- Merryland《Merryland》[FLAC/分轨][170.22MB]
- 庄锭欣 ELKIE《没有你的未来》[320K/MP3][15.78MB]