demo_01 创建并使用云函数

1. 创建并使用云函数

1.1 创建button调用方法:

      btn:

<button type="primary" @click="getList">调用get_list云函数</button>

      method:

getList(){
    uniCloud.callFunction({
        name:"get_list",
        data:{
            name: 'Bob',
            age: 18
        },
        success(res) {
            console.log(res);
        },
        fail(err) {
            console.log(err)
        }
    })
}
 
1.2 云函数
'use strict';
exports.main = async (event, context) => {
  //event为客户端上传的参数
  console.log('event : ' + event)
  //返回数据给客户端
  return {
      // 返回json对象,自己随便构造
      code: 200,
      msg: event.name + '的年龄是' + event.age,
      // 不知道为啥,这个 context 拿不到
      // context
  }
};
原文地址:https://www.cnblogs.com/luwei0915/p/13334927.html