<script>
export default {
data() {
return {
commentData:[],
page:1,
haseMore:true
}
},
methods: {
//分页请求数据
getData(){
if(this.haseMore) {
uni.showLoading({
title: '加载中...'
})
wx.cloud.database().collection('videoComment')
.limit(10) //每次请求10条记录
.skip((this.page-1)*10) //跳过已经查询的记录数量
.orderBy('addTime','desc')
.get({
success:(res) => {
//箭头函数能直接使用 this
console.log('请求成功',res)
this.commentData.push(...res.data) //云端返回的数据追加到commentData
this.page = this.page + 1 //页码加1
if(res.data.length < 10) {
//如果云端返回的数组长度小于10,说明没有更多数据了
this.haseMore = false
}
},
fail:(err) => {
console.log('请求失败',err)
},
complete:() => {
uni.hideLoading()
}
})
} else {
uni.showToast({
title: '没有更多数据了!',
icon:'none'
})
}
}
}
</script>
uniapp 微信小程序云开发分页加载数据
猜你喜欢
转载自blog.csdn.net/weixin_38946164/article/details/113881438
今日推荐
周排行