小程序 scroll-view 滚动刷新数据 增加swiper切换
来源:互联网 发布:抢票软件 编辑:程序博客网 时间:2024/05/28 20:20
scroll-view请看上一篇
场景:
在数据量很多的情况下,我们需要首先加载一部分数据,之后监测滚动更新数据
解决:
这时候可以使用 scroll-view 提供的接口来监控滚动情况
微信官方文档<scroll-view>里面提供了lower-threshold与bindscrolltolower来监控处理滑到到右边/底部的情况
代码如下
view
<view class="table"> <view class="tr"> <view class="th" wx:for="{{th}}">{{item}}</view> </view> <view class="scrollView"> <scroll-view scroll-y lower-threshold='1' bindscrolltolower="scrollBottom"> <view class="tr" wx:for="{{data}}"> <view class="td">{{item.user_name}}</view> <view class="td">{{item.user_points}}</view> </view> <view class="tr {{hasMore ? 'hasMore' : ' '}}"> <view class="td">没有更多数据了</view> </view> </scroll-view> </view></view>
js
Page({ data: { th: ["账号", '积分'], hasMore: true, data: [] }, onLoad: function() { this.getData() }, getData: function() { // 根据自身需要 与api交互获得数据 wx.hideLoading() }, scrollBottom: function() { var that = this if (that.data.hasMore) { wx.showLoading({ title: '更多数据加载中', icon: 'loading' }) that.getData() } }})
在view页面中
<scroll-view>的lower-threshold值默认为50
这时候需要把他修改的越小越好,最好为1或者0,不然会出现滑动多次触发函数的情况。
more
既然都做到这样了,不如再加上个滑动切换吧
这时候吧swiper组件也加上好了
view
<view class="tabBar"> <view id="{{index}}" class="tabBtn" wx:for="{{tabData}}" bindtap="tabChange">{{item}}</view> <view class="active" style="left:{{activeIndex*50}}%"></view></view><swiper current="{{activeIndex}}" bindchange="swiperChange"> <swiper-item> <view class="tablebox"> <view class="tr"> <view class="th">时间</view> <view class="th">账号</view> </view> <view class="scrollView" id="scrollView" style="{{style}}"> <scroll-view scroll-y> <view class="tr" wx:for="{{data01}}"> <view class="td">{{item.time}}</view> <view class="td">{{item.phone}}</view> </view> </scroll-view> </view> </view> </swiper-item> <swiper-item> <view class="tablebox"> <view class="tr"> <view class="th">时间</view> <view class="th">账号</view> </view> <view class="scrollView" style="{{style}}"> <scroll-view scroll-y> <view class="tr" wx:for="{{data02}}"> <view class="td">{{item.time}}</view> <view class="td">{{item.phone}}</view> </view> </scroll-view> </view> </view> </swiper-item></swiper>
js
Page({ data: { tabData: ['已绑定手机客户', '未绑定手机客户'], activeIndex: 0, data01: [], data02: [], hasMore: true},onLoad: function() { this.getData() this.getTop('#scrollView') }, getData: function() { // 根据自身需要 与api交互获得数据 wx.hideLoading() }, getTop: function(id) { var that = this wx.createSelectorQuery().select(id).boundingClientRect(function(rect) { console.log(rect) that.setData({ style: 'position: absolute;bottom: 0;width: 100%;top:' + rect.top + 'px' }) }).exec() }, scrollBottom: function() { var that = this if (that.data.hasMore) { wx.showLoading({ title: '更多数据加载中', icon: 'loading' }) that.getData() } }, tabChange(e) { console.log(e.currentTarget.id) let $index = parseInt(e.currentTarget.id) this.setData({ activeIndex: $index }) }, swiperChange(e) { console.log(e.detail.current) this.setData({ activeIndex: e.detail.current }) }})
阅读全文
0 0
- 小程序 scroll-view 滚动刷新数据 增加swiper切换
- 小程序 scroll-view
- 小程序scroll-view示例
- 微信小程序 scroll-view横向滚动 坑
- 微信小程序 scroll-view下拉刷新
- 连胜--小程序中滚动条的使用,wx.pageScrollTo和<scroll-view>的对比
- 小程序 使用scroll-view实现上拉加载,下拉刷新
- 小程序中scroll-view的使用
- 小程序scroll-view组件触发事件
- 微信小程序 swiper scroll-view height设置自适应 tab选项卡
- 微信小程序:使用swiper与scroll-view实现tab选项卡(2)
- 微信小程序-scroll-view滚动到指定位置(一)
- 微信小程序-scroll-view滚动到索引位置(二)
- 微信小程序-横向滑动scroll-view隐藏滚动条
- 微信小程序-scroll-view横向滚动和上拉加载
- 2.1.2微信小程序可滚动视图区域 scroll-view
- 微信小程序fixed定位下scroll-view滚动失效
- 小程序写tab和swiper切换结合效果
- Android framework系统默认设置修改
- hdu 6035(Colorful Tree)
- udp_socket with thread to contect with each other
- android studio的配置
- 如何理解泛型类的约束
- 小程序 scroll-view 滚动刷新数据 增加swiper切换
- CentOS 6 下升级安装Mysql 5.5 完整步骤
- Java类的实例化的几种方式
- vue项目中跳转到外部链接方法
- ECharts2.0横向显示柱状图
- MFC-为Button控件加载位图
- Http协议
- Python练手程序-03
- DIV 滚动条的自动显示隐藏