zzl00770

导航

getlimit 获取n条数据

//前端代码
getlimit() {
    uni.showLoading({
        title: '处理中...'
    })
    uniCloud.callFunction({
        name: 'getlimit',
        data:{
            name:'unicloud-test',
            data:{
                product:"uniCloud2"
            },
            limit:3

        }
    }).then((res) => {
        uni.hideLoading()
        uni.showModal({
            content: `查询成功,获取数据列表为:${JSON.stringify(res.result.data)}`,
            showCancel: false
        })
        console.log(res)
    }).catch((err) => {
        uni.hideLoading()
        uni.showModal({
            content: `查询失败,错误信息为:${err.message}`,
            showCancel: false
        })
        console.error(err)
    })
},
//云端代码
'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
    const collection = db.collection(event.name)
    const res = await collection.where(event.data).limit(event.limit).get()
    return res
};

 

posted on 2024-01-23 20:46  品味人生nuiapp  阅读(3)  评论(0编辑  收藏  举报