uniCloud 云函数

相对于云函数,官方更推荐使用 云对象

新建云函数

uniCloud 云函数_第1张图片
uniCloud 云函数_第2张图片
uniCloud 云函数_第3张图片

编辑云函数

uniCloud-aliyun/cloudfunctions/hello_func/index.js

'use strict';
exports.main = async (event, context) => {
	let {
		name
	} = event

	return `你好,${name}!`
};
  • 云函数接收的参数从event中解构获取

使用云函数

pages/index/index.vue

<button @click="use_hello_func">调用云函数button>
use_hello_func() {
	uniCloud.callFunction({
			name: 'hello_func',
			data: {
				name: '朝阳'
			}
		})
		.then(res => {
			console.log(res.result)
		});
},
  • uniCloud.callFunction() 调用云函数
  • 参数 name 的值为云函数的名称
  • 参数 data 的值为云函数的参数

开发调试时,使用的本地云函数

uniCloud 云函数_第4张图片

上传部署云函数

生产环境使用的云端云函数,所以需上传部署云函数

uniCloud 云函数_第5张图片
在这里插入图片描述

测试时,使用云端云函数

uniCloud 云函数_第6张图片

你可能感兴趣的:(#,uni-app,uniCloud)