您现在的位置是:网站首页> 编程资料编程资料
小程序实现简单分页组件_javascript技巧_
2023-05-24
334人已围观
简介 小程序实现简单分页组件_javascript技巧_
本文实例为大家分享了小程序实现简单分页组件的具体代码,供大家参考,具体内容如下
wxml:
共{{pagetotal}}页 上一页 Go 下一页
wxss:
/************分页样式****************/ .page_div{ display: flex; width: 100%; justify-content: flex-end; box-sizing: border-box; padding:20rpx; background-color: #fff; } .page_div .page_sum, .page_div .page_prev, .page_div .page_number_div, .page_div .page_next{ height: 50rpx; line-height: 50rpx; font-size:24rpx; color: #333; } .page_div .page_prev, .page_div .page_next{ background-color: #eee; padding:0 10rpx; margin:0 10rpx; } .page_div .page_number_div .pageGo{ display: inline-block; vertical-align: middle; width: 50rpx; box-sizing: border-box; background-color: #eee; text-align: center; margin:0 10rpx; } .page_div .page_number_div input{ width: 100rpx; display: inline-block; vertical-align: middle; text-align: center; border:1px solid #eee; } /************分页样式结束************/js:
Page({ data: { //分页数据 pageNumber:1, pagetotal:5, page:1 }, onLoad: function (options) { }, //input输入双向绑定数据 inputValue:function(e){ let name = e.currentTarget.dataset.name; let mapName ={}; mapName[name]=e.detail && e.detail.value; // console.log(mapName); this.setData(mapName); }, //上一页 prevFn:function(){ if(this.data.pageNumber <=1){ wx.showToast({ icon:'none', title: '已经是最前一页', }) return; } wx.showLoading({ title: '加载中...', }) this.setData({ pageNumber:Number(this.data.pageNumber)-1 }) console.log(this.data.pageNumber); setTimeout(function(){ wx.hideLoading() },1000) }, //下一页 nextFn:function(){ if(this.data.pageNumber === this.data.pagetotal){ wx.showToast({ icon:'none', title: '已经是最后一页', }) return; } wx.showLoading({ title: '加载中...', }) this.setData({ pageNumber:Number(this.data.pageNumber)+1 }) console.log(this.data.pageNumber); setTimeout(function(){ wx.hideLoading() },1000) }, //去到某一页 pageGo:function(){ console.log(Number(this.data.pageNumber)); if(Number(this.data.pageNumber) > this.data.pagetotal){ this.setData({ pageNumber:this.data.pagetotal }) }else if(Number(this.data.pageNumber) <= 0){ this.setData({ pageNumber:1 }) } console.log(Number(this.data.pageNumber)); wx.showLoading({ title: '加载中...', }) setTimeout(function(){ wx.hideLoading() },1000) } })效果图:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
您可能感兴趣的文章:
相关内容
- 微信小程序实现表格前后台分页_javascript技巧_
- 微信小程序实现列表分页功能_javascript技巧_
- 详解vue route介绍、基本使用、嵌套路由_vue.js_
- 小程序实现分页查询列表的模板_javascript技巧_
- Vue cli及Vue router实例详解_vue.js_
- vue+vux vux安装出现错误问题及解决_vue.js_
- vue安装less-loader依赖失败问题及解决方案_vue.js_
- 详解如何让页面与 iframe 进行通信_JavaScript_
- Vue图片裁剪功能实现代码_vue.js_
- JS 中的类Public,Private 和 Protected详解_javascript技巧_
