小程序 scroll-view 滚动刷新数据 增加swiper切换
2017-09-27 17:57
495 查看
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 }) }})
相关文章推荐
- 微信小程序: swiper 的 swiper-item 下 scroll-view 无法滚动
- 微信小程序-scroll-view滚动到索引位置(二)
- 微信小程序----scroll-view组件(MUI索引列表)滚动动画
- 微信小程序scroll-view实现滚动穿透和阻止滚动的方法
- 微信小程序-scroll-view横向滚动和上拉加载
- 微信小程序 scroll-view滚动到索引位置
- 2.1.2微信小程序可滚动视图区域 scroll-view
- Android中仿淘宝首页顶部滚动自定义HorizontalScrollView定时水平自动切换图片
- 小程序横向scroll-view组件自动滚动到某个view
- 微信小程序scroll-view实现横向滚动和上拉加载示例
- 微信小程序Swiper+wx.request 数据绑定刷新
- 小程序 - swiper除了左右切换还有上下滚动超出屏幕的内容
- 小程序scroll-view横向滚动
- 动态地往datagirdview中添加数据,当所添加的数据超过datagridview的显示范围后,滚动条就无法显示,程序出现假死状态,(scrollbars=both)
- 微信小程序例子——如何使用scroll-view组件实现视图垂直滚动
- ScrollView+ViewPager(上下滚动+自动切换图片)
- 小程序 - swiper除了左右切换还有上下滚动超出屏幕的内容
- iOS 刷新tableView的某一行的row的时候,row的高度增加,数据也增加。
- 微信小程序上拉刷新和下拉加载2种方法实现,onPullDownRefresh,scroll-view使用
- scrollerView内的数据每次刷新都会滚动到底部处理