小程序加载数据
index.wxml
<view class="page__bd">
<mp-loading type="circle" show="{{loading}}"></mp-loading>
<view class="weui-loadmore weui-loadmore_line" wx:if="{{!loading}}">
<view class="weui-loadmore__tips weui-loadmore__tips_in-line">暂无数据</view>
</view>
</view>
index.json
"usingComponents": {
"mp-loading": "../../components/loading/loading"
}
index.js
getList: function(){
return new Promise((resolve, reject) => {
let that = this;
that.setData({loading:true})
let page = that.data.page;
//读取users表数据
wx.cloud.callFunction({
name: "get_zhao",
data: {
page: page,
limit: that.data.limit
}
})
.then(res=>{
console.log('--->',res)
if (res.result.data.length > 0) {
if (res.result.total < that.data.limit) {
that.setData({ loading: false, nomore: true })
}
wx.hideLoading()
that.data.page++
let list = that.data.list;
console.log("读取成功", list)
for (let i = 0; i < res.result.data.length; i++) {
list.push(res.result.data[i])
}
that.setData({ list: list, total: res.result.total})
} else {
wx.hideLoading()
that.setData({loading:false,nomore:true})
}
})
})
},