传统的基础云函数操作
先直接写一个方法获取云数据库中的数据
'use strict';
const db=uniCloud.database()
exports.main = async (event, context) => {
return await db.collection("article").get();
};
onLoad() {
this.getData();
},
methods: {
getData(){
uniCloud.callFunction({
name:"cloudFun1"
}).then(res=>{
console.log(res);
})
}
}
}
传递一个参数,并在云函数中接收
获取两条数据,在页面中传递2,在云函数中接收并使用limit查询
methods: {
getData(){
uniCloud.callFunction({
name:"cloudFun1",
data:{
num:2
}
}).then(res=>{
console.log(res);
})
}
}
'use strict';
const db=uniCloud.database()
exports.main = async (event, context) => {
let {num} = event;
return await db.collection("article").limit(num).get();
};