iis服务器助手广告广告
返回顶部
首页 > 资讯 > 前端开发 > VUE >Vue.js如何结合bootstrap实现分页控件
  • 951
分享到

Vue.js如何结合bootstrap实现分页控件

2024-04-02 19:04:59 951人浏览 独家记忆
摘要

这篇文章给大家分享的是有关vue.js如何结合bootstrap实现分页控件的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。具体内容如下效果如下实现代码:<!DOCTYPE&

这篇文章给大家分享的是有关vue.js如何结合bootstrap实现分页控件的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

具体内容如下

效果如下

Vue.js如何结合bootstrap实现分页控件

Vue.js如何结合bootstrap实现分页控件

Vue.js如何结合bootstrap实现分页控件

实现代码:

<!DOCTYPE html> 
<html> 
<head> 
 <meta charset="utf-8" /> 
 <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 
 <title> Vue-PagerTest</title> 
 <link rel="stylesheet" href="/lib/bootstrap/dist/CSS/bootstrap.css" rel="external nofollow" /> 
</head> 
<body> 
 <div class="container body-content"> 
 <div id="test" class="fORM-group"> 
  <div class="form-group"> 
  <div class="page-header"> 
   数据 
  </div> 
  <table class="table table-bordered table-responsive table-striped"> 
   <tr> 
   <th>姓名</th> 
   <th>年龄</th> 
   <th>删除信息</th> 
   </tr> 
   <tr v-for="item in arrayData"> 
   <td class="text-center">{{item.name}}</td> 
   <td>{{item.age}}</td> 
   <td><a href="javascript:void(0)" rel="external nofollow" v-on:click="deleteItem($index,item.age)">del</a></td> 
   </tr> 
  </table> 
  <div class="page-header">分页</div> 
  <div class="pager" id="pager"> 
   <span class="form-inline"> 
   <select class="form-control" v-model="pagesize" v-on:change="showPage(pageCurrent,$event,true)" number> 
    <option value="10">10</option> 
    <option value="20">20</option> 
    <option value="30">30</option> 
    <option value="40">40</option> 
   </select> 
   </span> 
   <template v-for="item in pageCount+1"> 
   <span v-if="item==1" class="btn btn-default" v-on:click="showPage(1,$event)"> 
    首页 
   </span> 
   <span v-if="item==1" class="btn btn-default" v-on:click="showPage(pageCurrent-1,$event)"> 
    上一页 
   </span> 
   <span v-if="item==1" class="btn btn-default" v-on:click="showPage(item,$event)" v-bind:class="item==pageCurrent?'active':''"> 
    {{item}} 
   </span> 
   <span v-if="item==1&&item<showPagesStart-1" class="btn btn-default disabled"> 
    ... 
   </span> 
   <span v-if="item>1&&item<=pageCount-1&&item>=showPagesStart&&item<=showPageEnd&&item<=pageCount" class="btn btn-default" v-on:click="showPage(item,$event)" <span > v-bind:class="item==pageCurrent?'active':''"</span><span >></span> 
    {{item}} 
   </span> 
   <span v-if="item==pageCount&&item>showPageEnd+1" class="btn btn-default disabled"> 
    ... 
   </span> 
   <span v-if="item==pageCount" class="btn btn-default" v-on:click="showPage(item,$event)" <span >v-bind:class="item==pageCurrent?'active':''"</span><span >></span> 
    {{item}} 
   </span> 
   <span v-if="item==pageCount" class="btn btn-default" v-on:click="showPage(pageCurrent+1,$event)"> 
    下一页 
   </span> 
   <span v-if="item==pageCount" class="btn btn-default" v-on:click="showPage(pageCount,$event)"> 
    尾页 
   </span> 
   </template> 
   <span class="form-inline"> 
   <input class="pageIndex form-control"  type="text" v-model="pageCurrent | onlyNumeric" v-on:keyup.enter="showPage(pageCurrent,$event,true)" /> 
   </span> 
   <span>{{pageCurrent}}/{{pageCount}}</span> 
  </div> 
  </div> 
 </div> 
 <hr /> 
 <footer> 
  <p>&copy; 2016 - 笑问苍天丶</p> 
 </footer> 
 </div> 
 
 
 <script src="/lib/Jquery/dist/jquery.js"></script> 
 <script src="/lib/bootstrap/dist/js/bootstrap.js"></script> 
 <script src="/lib/vue.js"></script> 
 <script> 
 //只能输入正整数过滤器 
 Vue.filter('onlyNumeric', { 
  // model -> view 
  // 在更新 `<input>` 元素之前格式化值 
  read: function (val) { 
  return val; 
  }, 
  // view -> model 
  // 在写回数据之前格式化值 
  write: function (val, oldVal) { 
  var number = +val.replace(/[^\d]/g, '') 
  return isNaN(number) ? 1 : parseFloat(number.toFixed(2)) 
  } 
 }) 
 
 //数组删除某项功能 
 Array.prototype.remove = function (dx) { 
  if (isNaN(dx) || dx > this.length) { return false; } 
  for (var i = 0, n = 0; i < this.length; i++) { 
  if (this[i] != this[dx]) { 
   this[n++] = this[i] 
  } 
  } 
  this.length -= 1 
 } 
 
 var vue = new Vue({ 
  el: "#test", 
  data: { 
  //总项目数 
  totalCount: 200, 
  //分页数 
  pageCount: 20, 
  //当前页面 
  pageCurrent: 1, 
  //分页大小 
  pagesize: 10, 
  //显示分页按钮数 
  showPages: 11, 
  //开始显示的分页按钮 
  showPagesStart: 1, 
  //结束显示的分页按钮 
  showPageEnd: 100, 
  //分页数据 
  arrayData: [] 
  }, 
  methods: { 
  //分页方法 
  showPage: function (pageIndex, $event, forceRefresh) { 
 
   if (pageIndex > 0) { 
 
 
   if (pageIndex > this.pageCount) { 
    pageIndex = this.pageCount; 
   } 
 
   //判断数据是否需要更新 
   var currentPageCount = Math.ceil(this.totalCount / this.pagesize); 
   if (currentPageCount != this.pageCount) { 
    pageIndex = 1; 
    this.pageCount = currentPageCount; 
   } 
   else if (this.pageCurrent == pageIndex && currentPageCount == this.pageCount && typeof (forceRefresh) == "undefined") { 
    console.log("not refresh"); 
    return; 
   } 
 
   //测试数据 随机生成的 
   var newPageInfo = []; 
   for (var i = 0; i < this.pagesize; i++) { 
    newPageInfo[newPageInfo.length] = { 
    name: "test" + (i + (pageIndex - 1) * 20), 
    age: (i + (pageIndex - 1) * 20) 
    }; 
   } 
   this.pageCurrent = pageIndex; 
   this.arrayData = newPageInfo; 
 
   //计算分页按钮数据 
   if (this.pageCount > this.showPages) { 
    if (pageIndex <= (this.showPages - 1) / 2) { 
    this.showPagesStart = 1; 
    this.showPageEnd = this.showPages - 1; 
    console.log("showPage1") 
    } 
    else if (pageIndex >= this.pageCount - (this.showPages - 3) / 2) { 
    this.showPagesStart = this.pageCount - this.showPages + 2; 
    this.showPageEnd = this.pageCount; 
    console.log("showPage2") 
    } 
    else { 
    console.log("showPage3") 
    this.showPagesStart = pageIndex - (this.showPages - 3) / 2; 
    this.showPageEnd = pageIndex + (this.showPages - 3) / 2; 
    } 
   } 
   console.log("showPagesStart:" + this.showPagesStart + ",showPageEnd:" + this.showPageEnd + ",pageIndex:" + pageIndex); 
   } 
 
  } 
  , deleteItem: function (index, age) { 
   if (confirm('确定要删除吗')) { 
   //console.log(index, age); 
 
   var newArray = []; 
   for (var i = 0; i < this.arrayData.length; i++) { 
    if (i != index) { 
    newArray[newArray.length] = this.arrayData[i]; 
    } 
   } 
   this.arrayData = newArray; 
   } 
  } 
  } 
 }); 
 vue.$watch("arrayData", function (value) { 
  //console.log("==============arrayData begin=============="); 
  //console.log(value==vue.arrayData); 
  //console.log(vue.arrayData); 
  //console.log("==============arrayData end=============="); 
 }); 
 vue.showPage(vue.pageCurrent, null, true); 
 </script> 
</body> 
</html>

感谢各位的阅读!关于“Vue.js如何结合bootstrap实现分页控件”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

--结束END--

本文标题: Vue.js如何结合bootstrap实现分页控件

本文链接: https://www.lsjlt.com/news/69344.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Vue.js如何结合bootstrap实现分页控件
    这篇文章给大家分享的是有关Vue.js如何结合bootstrap实现分页控件的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。具体内容如下效果如下实现代码:<!DOCTYPE&...
    99+
    2024-04-02
  • Vue.js+bootstrap前端如何实现分页和排序
    小编给大家分享一下Vue.js+bootstrap前端如何实现分页和排序,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!效果图:语法:数据绑定 {{...}}或者v-model<td&...
    99+
    2024-04-02
  • Vue.js分页组件如何实现diVuePagination
    这篇文章给大家分享的是有关Vue.js分页组件如何实现diVuePagination的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。一.介绍Vue.js 是什么Vue (读音 /v...
    99+
    2024-04-02
  • 如何使用bootstrap实现分页
    这篇文章主要讲解了“如何使用bootstrap实现分页”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何使用bootstrap实现分页”吧! ...
    99+
    2024-04-02
  • bootstrap中如何实现table分页
    小编给大家分享一下bootstrap中如何实现table分页,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!bootstrap table分页的两种方式:前端分页:...
    99+
    2023-06-14
  • Vue.js如何实现表单控件
    小编给大家分享一下Vue.js如何实现表单控件,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!概念说明v-model指令:在表单控...
    99+
    2024-04-02
  • Node.js中Bootstrap-table如何实现分页
    这篇文章给大家分享的是有关Node.js中Bootstrap-table如何实现分页的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。1、Bootstrap-table使用官方文档:...
    99+
    2024-04-02
  • angularjs+bootstrap如何实现自定义分页
    这篇文章主要介绍angularjs+bootstrap如何实现自定义分页,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!目前在做一个java web页面,没有使用到框架的分页,所以需要...
    99+
    2024-04-02
  • Vue和Bootstrap结合实现响应式网页设计
    现如今,随着移动互联网的发展,越来越多的用户选择通过移动设备来浏览网页内容。因此,响应式网页设计成为了网页设计的时尚流行趋势。Vue和Bootstrap作为两个非常受欢迎的前端开发框架,可以帮助我们快速有效地创建响应式网页设计。Vue是一个...
    99+
    2023-12-27
    Vue (个字) Bootstrap (个字) 响应式网页设计 (个字)
  • bootstrap分页插件如何使用
    要使用Bootstrap分页插件,您需要遵循以下步骤:1. 引入Bootstrap的CSS和JavaScript文件。在您的HTML...
    99+
    2023-08-24
    bootstrap
  • vue.js中怎么实现一个分页插件
    这篇文章将为大家详细讲解有关vue.js中怎么实现一个分页插件,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。html代码:<div clas...
    99+
    2024-04-02
  • Angualrjs和bootstrap相结合如何实现数据表格table
    这篇文章主要介绍Angualrjs和bootstrap相结合如何实现数据表格table,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!AngularJS的数据表格需要使用anguala...
    99+
    2024-04-02
  • 如何使用vue.js制作分页组件
    今天小编给大家分享一下如何使用vue.js制作分页组件的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。首先是index.htm...
    99+
    2023-07-04
  • GridView控件实现分页功能
    GridView控件本身并不直接支持分页功能,但可以通过其他方法来实现分页功能。一种常见的方法是使用Pager控件来实现分页。Pag...
    99+
    2023-09-20
    GridView
  • Bootstrap如何实现翻页效果
    这篇文章主要介绍Bootstrap如何实现翻页效果,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!效果图最后一页时:最开始一页时:实现①、翻页组件的布局<%@ page...
    99+
    2024-04-02
  • vue.js分页中如何实现单击页码更换页面内容
    这篇文章主要为大家展示了“vue.js分页中如何实现单击页码更换页面内容”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“vue.js分页中如何实现单击页码更换页面...
    99+
    2024-04-02
  • angularjs结合pagination插件实现分页功能的示例分析
    小编给大家分享一下angularjs结合pagination插件实现分页功能的示例分析,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!angularjs与pagination插件可以完美实现...
    99+
    2024-04-02
  • Bootstrap中导航条和分页导航如何实现
    这篇文章主要介绍Bootstrap中导航条和分页导航如何实现,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完! 本篇文章带大家了解一下Bootstrap中的导...
    99+
    2024-04-02
  • MyBatis-Plus结合Layui实现分页方法
    MyBatis-Plus 使用简单,内置通用 Mapper、通用 Service,仅仅通过少量配置,即可实现单表大部分 CRUD 操作。下面介绍使用 service 中的 page ...
    99+
    2024-04-02
  • require.js与bootstrap结合怎么实现页面登录和页面跳转功能
    这篇文章主要介绍了require.js与bootstrap结合怎么实现页面登录和页面跳转功能,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。页...
    99+
    2024-04-02
软考高级职称资格查询
推荐阅读
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作