开始使用云函数
get_list
'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log('event : ', event)
//返回数据给客户端
return {
code:200,
msg:event.name+"的年龄"+event.age,
context
}
};
index.vue
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{
{title}}</text>
</view>
<button @click="open">执行云函数</button>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
open(){
uniCloud.callFunction({
name:"get_list",
data:{
name:"liming",
age:18
},
success(res) {
console.log(res)
},
fail() {
}
})
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
云数据库的添加和删除
添加
get_list.vue
'use strict';
const db=uniCloud.database()
exports.main = async (event, context) => {
const collection=db.collection("user")
let res=await collection.add([
{
name:'uni-app'},{
name:'html',type:'前端'}
])
console.log("数据插入:")
console.log(JSON.stringify(res))
return {
}
};
删除
get_list
'use strict';
const db=uniCloud.database