
正文
微信小程序 下拉刷新
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
<scroll-view class='scroll-view-container' scroll-y="true" bindscrolltolower='scrollToLower' bindscrolltoupper='scrollToUpper' lower-threshold='30' upper-threshold='0'> <view class="box" wx:for="{{list.data}}" wx:key="id"> 省略掉这一部分代码,自己添加渲染 </view> <view class='data-loading' hidden='{{hidden}}'> 数据加载中... </view> </scroll-view>
js
` onLoad: function (options) {
this.loadData(true)
}
scrollToUpper: function(e) {
wx.showToast({
title: '触顶了...',
})
},
scrollToLower: function(e) {
console.info('scrollToLower', e);
var hidden = this.data.hidden,
loadingData = this.data.loadingData,that = this;
if (hidden) {
this.setData({
hidden: false
});
console.info(this.data.hidden);
}
if (loadingData) {
return;
}
this.setData({
loadingData: true
});
// 加载数据,模拟耗时操作
wx.showLoading({
title: '数据加载中...',
});setTimeout(function() {
that.loadData(true, () => {
console.log(true)
that.setData({
hidden: true,
loadingData: false
});
wx.hideLoading();
});
console.info('上拉数据加载完成.');
}, 2000);
},
loadData: function(tail, callback) {
var that = this;
wx.request({
url: '自己定义。。。。。。',
method: 'GET',
header: {
'content-type': 'application/x-www-form-urlencoded' // 默认值
},
success(res) {
that.setData({
list: res.data
})
// }
if (callback) {
callback();
}
}
})
}`







