vue.js 分页

迈不过友情╰ 2021-08-28 17:07 493阅读 0赞

先上样式的代码

  1. <style> .fenye { font-weight: 900;height: 40px;text-align: center;color: #888;margin: 0 auto;background: #f2f2f2;}
  2. .pagelist { font-size: 0;background: #fff;height: 50px;line-height: 50px;}
  3. .pagelist span { font-size: 14px;}
  4. .pagelist .jump { border: 1px solid #ccc;padding: 5px 8px;-webkit-border-radius: 4px;-moz-border-radius: 4px;border-radius: 4px;cursor: pointer;margin-left: 5px;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none;-khtml-user-select:none;user-select:none;}
  5. .pagelist .bgprimary { cursor: default;color: #fff;background: #fa7804;border-color: #fa7804;}
  6. .jumpinp input { width: 55px;height: 26px;font-size: 13px;border: 1px solid #ccc-webkit-border-radius: 4px;-moz-border-radius: 4px;border-radius: 4px;text-align: center;}
  7. .ellipsis { padding: 0px 8px;}
  8. .jumppoint { margin-left: 30px;}
  9. .pagelist .gobtn { font-size: 12px;}
  10. .bgprimary { cursor: default;color: #fff;background: #337ab7;border-color: #337ab7;}
  11. .pagelist .jump.disabled{ pointer-events: none; background: #ddd;}
  12. </style>

html 部分的代码

  1. <div class="fenye" id="fenye" v-show="show">
  2. <div class="pagelist">
  3. <span class="jump" @click="jumpPage(1)">首页</span>
  4. <span class="jump" :class="{disabled:pstart}" @click="up_current_page">上一页</span>
  5. <span class="jump" v-for="num in indexs" :class="{bgprimary:current_page==num}" @click="jumpPage(num)">{ { num}}</span>
  6. <span :class="{disabled:pend}" class="jump" @click="down_current_page">下一页</span>
  7. <span class="jump" @click="jumpPage(pages)">尾页</span>
  8. <!--<span class="jumppoint">跳转到:</span>
  9. <span class="jumpinp"><input type="text" v-model="changePage"></span>
  10. <span class="jump gobtn" @click="jumpPage(changePage)">跳转</span>-->
  11. </div>
  12. </div>

JS部分的代码

  1. <script src="js/vue.js"></script><!--引入vue.js文件,路径已实际情况为准-->
  2. <script>
  3. var newlist = new Vue({
  4. el: '#fenye',
  5. data: {
  6. //分页插件
  7. current_page: 0, //当前页
  8. pages: 0, //总页数
  9. changePage:'',//跳转页
  10. nowIndex:0,
  11. show_page:5,//显示页码的数量
  12. },
  13. computed:{
  14. show:function(){
  15. return this.pages && this.pages !=1
  16. },
  17. pstart: function() {
  18. return this.current_page == 1;
  19. },
  20. pend: function() {
  21. return this.current_page == this.pages;
  22. },
  23. efont: function() {
  24. if (this.pages <= this.show_page) return false;
  25. return this.current_page > 5
  26. },
  27. ebehind: function() {
  28. if (this.pages <= this.show_page) return false;
  29. var nowAy = this.indexs;
  30. return nowAy[nowAy.length - 1] != this.pages;
  31. },
  32. indexs: function() {
  33. var left = 1,
  34. right = this.pages,
  35. ar = [];
  36. if (this.pages >= this.show_page) {
  37. if (this.current_page > 5 && this.current_page < this.pages - 4) {
  38. left = Number(this.current_page) - 2;
  39. right = Number(this.current_page) + 2;
  40. }else {
  41. if (this.current_page <= 5) {
  42. left = 1;
  43. right = this.show_page;
  44. } else {
  45. right = this.pages;
  46. left = this.pages - 4;
  47. }
  48. }
  49. }
  50. while (left <= right) {
  51. ar.push(left);
  52. left++;
  53. }
  54. return ar;
  55. },
  56. },
  57. methods: {
  58. //跳转分页
  59. jumpPage: function(page) {
  60. var that = this;
  61. that .current_page = page;
  62. //this.lists(); //执行业务逻辑
  63. },
  64. //上一页
  65. up_current_page:function(){
  66. var that = this;
  67. that .current_page--;
  68. //this.lists(); //执行业务逻辑
  69. },
  70. //下一页
  71. down_current_page:function(){
  72. var that = this;
  73. that .current_page++;
  74. //this.lists(); //执行业务逻辑
  75. },
  76. },
  77. })
  78. </script>

发表评论

表情:
评论列表 (有 0 条评论,493人围观)

还没有评论,来说两句吧...

相关阅读

    相关

    [几种分页方法效率比较][Link 1] ASP.net 的DataGrid 控件的内置分页功能一直不被看好,原因是它先把所有数据从数据库读出来再进行分页。在数据量很大的