第一步
查询数据库总条数设置页大小,计算出多少页
db.collection(集合名).where({
参数
}).count({
success: function(res) {
//返回总条数
that.data.totalCount = res.total;
var yeshu = Math.ceil(res.total / that.data.pageSize)
that.setData({
yeshu: yeshu
})
console.log(yeshu)
}
})
//获取设置条的数据
try {
db.collection(集合名).where({
参数
})
.limit(that.data.pageSize)
.get({
success: function(res) {
}
})
} catch (e) {
//报错异常
console.log(e)
}
使用limit方法限制每页多少条数据,查询集合绑定渲染
const db = wx.cloud.database();
//初始化数据库
db.collection(集合名).where({
参数名
})
.skip(skilSize)
.limit(that.data.pageSize)
.get({
success: function(res) {
}
})
配合云开发skip 和 limit 进行分页控制
skip 分页函数 参数 第几页
查询返回数据绑定渲染
分页控件
wxml
<block wx:if="{{listdata.length!=0}}">
<view class="pagenum">
<text>共{{yeshu}}页</text>
<block wx:if="{{yeshu!=1}}">
<label bindtap="topClick" class="topcl">上一页</label>
<label bindtap="downClick" class="topcl">下一页</label>
</block>
</view>
</block>
wxss
.pagenum {
font-size: calc(28vmin / 7.5);
text-align: center;
margin-top: calc(40vmin / 7.5);
margin-bottom: calc(40vmin / 7.5);
}
.pagenum label {
margin-left: calc(40vmin / 7.5);
}
.topcl{width: calc(130vmin / 7.5);line-height: calc(70vmin / 7.5);display: inline-block;background: #C0C0C0;border-radius: 7px}