• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

基于vue.js的分页插件详解

vue 搞代码 4年前 (2022-01-08) 50次浏览 已收录 0个评论

这篇文章主要为大家详细介绍了基于vue.js的分页插件,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

Vue.js 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件。想了解更多,请戳http://cn.vuejs.org/

html代码:

 <div class="page-bar"> <ul> <li style="width: 11%">  <<</li><li> {{index}}</li><li style="width: 11%"> >></li><li style="width: 22%;margin-left: 7%">共<i>{{all}}</i>页</li></ul></div>

css部分,可根据自己的实际需要进行调整:

 .page-bar { margin-top: 21px; margin-left: 11%; } .page-bar ul, .page-bar li { margin: 0px; padding: 0px; } .page-bar ul li { list-style: none; border: 1px solid #ddd; text-decoration: none; position: relative; float: left; text-align: center; padding: 1px 0; margin-left: -1px; line-height: 1.42857143; color: #337ab7; cursor: pointer; width: 8%; } .page-bar li:first-child>a { margin-left: 0px } .page-bar .active a { color: #fff; c<i style="color:transparent">本文来源gaodai$ma#com搞$$代**码)网8</i>ursor: default; background-color: #337ab7; border-color: #337ab7; } .page-bar i { font-style: normal; color: #d44950; margin: 0px 4px; font-size: 12px; } 

js部分:

首先要创建一个基本组件

 var vm = new Vue({ el: 'body', data: { list: null, all: 1, //总页数 cur: 1, //当前页码 }, 

继而要利用computed计算页码,

 computed: { indexs: function(index) { var left = 1; var right = this.all; var ar = []; if (this.all >= 11) { if (this.cur > 5 && this.cur <this.all - 4) { left = this.cur - 5; right = this.cur + 4; } else { if (this.cur <= 5) { left = 1; right = 10; } else { right = this.all; left = this.all - 9; } } } while (left <= right) { ar.push(left); left++; } return ar; }, showLast: function() { if (this.cur == this.all) { return false } return true }, showFirst: function() { if (this.cur == 1) { return false } return true } } 

要给 元素加v-on:click=”cur++”事件,所以要在vue里加method方法:

 methods: { btnClick: function(items) { //页码点击事件 if (items != this.cur) { this.cur = items } } }, 

其实到这里基本上就差不多了,但是可以优化一下,当用户触发点击事件时,页面发生改变,这时要通知其他组件做出改变。

 watch: { cur: function(oldValue, newValue) { console.log(arguments) } } 

观察了cur数据当它改变的时候,可以获取前后值。然后通知其他组件。

后期会在个人GitHub上提交完整版代码

补充效果图展示

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持gaodaima搞代码网

以上就是基于vue.js的分页插件详解的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:基于vue.js的分页插件详解

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址