微信小程序加载更多 点击查看更多

<view wx:for="{{duanziInfo}}" wx:for-item="name" wx:for-index="id"> <view> <view> <text>{{name.content}}</text> </view> </view> </view> <view> <button type="default" size="default" loading="{{loading}}" disabled="{{disabled}}" bindtap="setLoading"> {{loadText}} </button> </view>

加载更多按钮绑定setLoading

index.js文件代码如下

Page({ data: { loadText:'加载更多', duanziInfo:[] }, //初始化请求 onLoad: function (res) { var that = this //内容 wx.request({ url: 'http://xxxxx.com/index.php?m=Industry&a=getDuanziInfo', data: {token:token}, method: 'GET', success: function(res){ console.log(res.data.result) //打印初始化数据 that.setData({ duanziInfo:res.data.result }) } }) }, //加载更多 setLoading: function(e) { var duanziInfoBefore = this.data.duanziInfo var that = this wx.showToast({ //期间为了显示效果可以添加一个过度的弹出框提示“加载中” title: '加载中', icon: 'loading', duration: 200 }) wx.request({ url: 'http://xxxxx.com/index.php?m=Industry&a=getDuanziInfo', data: {token:token}, method: 'GET', success: function(res){ console.log(duanziInfoBefore.concat(res.data.result)) //打印拼接之后数据 that.setData({ loadText:"数据请求中", loading:true, duanziInfo:duanziInfoBefore.concat(res.data.result), loadText:"加载更多", loading:false, }) } }) } })

初始化和加载更多中的打印数据如下

微信小程序加载更多 点击查看更多

(以上是点击查看更多,还可以根据距离视图区域的距离来加载更多,具体实现是将视图用<scroll-view>标签,并给其一个固定高度,在给定参数中设置距离像素触发事件。具体文档:)

为大家推荐现在关注度比较高的微信小程序教程一篇:《微信小程序开发教程》小编为大家精心整理的,希望喜欢。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwxgdp.html