Vue实现简易翻页效果源码分享
2018-12-03 09:26
603 查看
源码如下:
<html> <head> <meta charset="UTF-8"> <title>slidePage</title> <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script> <style type="text/css"> *{ margin: 0; padding: 0; } .container { width: 100%; margin: 0 auto; text-align: center; } .content{ font-size: 400px } .leftBtn{ width: 45px; height: 45px; margin-right: 15px; } .rightBtn{ width: 45px; height: 45px; margin-left: 15px; } </style> </head> <body> <div id='root'> <div v-if="numberArr.length == 0">{{showMessage}}</div> <div class="container" v-for="(item, index) in getCurPageContent(numberArr, curPage, itemNumPerPage)" :key="index"> <div class="content">{{item}}</div> <div class="pageButtonList"> <button class="leftBtn" @click="handleClick('leftBtn')"><</button> <span class="pagination">{{curPage}}/{{totalPage}}</span> <button class="rightBtn" @click="handleClick('rightBtn')">></button> </div> </div> </div> <script> new Vue({ el: "#root", data(){ return { showMessage: 'No number', content:'', numberArr: [1, 2, 3, 4], curPage: 1, totalPage: 1, itemNumPerPage: 1 } }, mounted() { this.init() }, methods:{ init(){ this.totalPage = Math.ceil(this.numberArr.length / this.itemNumPerPage) this.totalPage = this.totalPage < 1 ? 1 : this.totalPage }, getCurPageContent: function(numberArr, curPage, itemNumPerPage){ return numberArr.filter(function(element, index){ if(index >= (curPage -1)* itemNumPerPage && index < curPage *itemNumPerPage){ return true }else{ return false } }) }, handleClick: function(arg){ if(arg == 'leftBtn'){ this.curPage = this.curPage > 1 ? --this.curPage : this.totalPage }else if (arg == 'rightBtn'){ this.curPage = this.curPage < this.totalPage ? ++this.curPage: 1 } } // handleLeftClick: function(){ // if(this.curPage > 1){ // this.curPage -- // }else{ // this.curPage = this.totalPage // } // }, // handleRightClick: function(){ // if(this.curPage < this.totalPage){ // this.curPage ++ // }else{ // this.curPage = 1 // } // } } }) </script> </body> </html>
效果如下所示,点击左右能切换页面:
总结
以上所述是小编给大家介绍的Vue实现简易翻页效果源码分享,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章:
相关文章推荐
- Vue实现简易翻页效果源码分享
- Android编程实现简易弹幕效果示例【附demo源码下载】
- [分享]OpenGL实现的翻页效果
- vue简易指引用户向下翻阅悬浮效果箭头实现
- jQuery实现百叶窗焦点图动画效果代码分享(附源码下载)
- vue.js+mock.js+node.js实现移动端翻页效果
- 词Ci首页效果实现介绍及源码分享
- vue 实现 pager 组件翻页效果
- jQuery实现百叶窗焦点图动画效果代码分享(附源码下载)
- vue-awesome-swiper - 基于vue实现h5滑动翻页效果
- ios开发学习-页面控制样式翻页、文字、颜色等效果源码分享
- 利用GPU实现翻页效果(分享自知乎网)
- 源码下载java利用jquery和smartupload实现头像上传切割效果
- 分享一个jquery插件:实现类似淘宝上鼠标经过图片右侧显示大图的效果
- vue 指令之气泡提示效果的实现代码
- Android编程实现可滑动的开关效果(附demo源码下载)
- vue2.0使用swiper组件实现轮播效果
- Vue页面跳转动画效果的实现方法