云函数

开始使用云函数

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 {
   
		
	}
};

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WCdU8m3F-1612678269483)(F:\Uni-app.assets\image-20210207103613412.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JvidZtrZ-1612678269486)(F:\Uni-app.assets\image-20210207103627410.png)]

删除

get_list

'use strict';
const db=uniCloud.database
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值