当前位置:网站首页>小程序通过云函数操作数据库【使用get取数据库】
小程序通过云函数操作数据库【使用get取数据库】
2022-08-01 06:42:00 【元宇宙iwemeta】
云函数定义为getdatas,以下是云函数里面的index.js ,注意,此时的云函数入口函数里并不需要写回调函数,因为其得到的结果是直接返回即可了
// 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init() const db = cloud.database() // 云函数入口函数 exports.main = async (event, context) => { return await db.collection("user_info").get(); }
这里已经在云数据库里面有一个名为“user_info”的集合,如下:
在page_02的js里面添加以下的函数
cloudData:function(){ wx.cloud.callFunction({ name:"getdatas" }).then(res=>{ console.log(res) }).catch(err=>{ console.error(err) }) }
page_02的wxml如下
<view class="btn-area"> <button bindtap='cloudData'>Cloud</button> </view>
结果如下:
边栏推荐
猜你喜欢
随机推荐
mysql的行锁和间隙锁
用位运算为你的程序加速
Speed up your programs with bitwise operations
Srping中bean的生命周期
More than 2022 cattle guest school game 4 yue
crypto-js使用
leetcode43 字符串相乘
The BP neural network based on MATLAB voice characteristic signal classification
NUMPY
从离线到实时对客,湖仓一体释放全量数据价值
The Bean's life cycle
first unique character in characters
第02章 MySQL的数据目录【1.MySQL架构篇】【MySQL高级】
小白的0基础教程SQL: 安装MYSQL 03
matlab simulink 粒子群优化模糊pid控制的电机泵
Causes and solutions of lock table
Qt Widget 项目对qml的加载实例
matplotlib pyplot
史上超强最常用SQL语句大全
LeetCode 0149. Maximum number of points on a line