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

相关文章:

  • 2022-12-23
  • 2021-11-19
  • 2021-12-08
  • 2021-11-20
  • 2022-12-23
  • 2021-11-22
  • 2022-01-12
  • 2021-04-11
猜你喜欢
  • 2022-02-08
  • 2021-11-11
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-08-03
相关资源
相似解决方案