共计 543 个字符,预计需要花费 2 分钟才能阅读完成。
- 云函数(能够了解为一般开发中的接口的实现)
cloudfunctions
目录右键新建 node.js 云函数
例如helloWord
- 须要在终端里 去装置云函数
helloWord
cd cloudfunctions/helloWord
npm i
- 装置实现后,这时的云函数就是能够应用了(函数的内容是用户的根本信息)。
- 能够在小程序
index.js
的onload
生命周期里去调试应用一下(调用云函数就像是调用接口)。
const result = await wx.cloud.callFunction({name:'helloWord'})
console.log(result)
- 应用云函数进行数据库的查问和批改
- 数据库反对
async/await
操作 - 在进行数据库
add
时 须要新建一个数据库汇合(表)也无需定义表构造 db.collection
能够进行表的查问操作db.command
能够进行简单的子表查问.where
前面跟查问条件.get
是查问后果
const db = wx.cloud.database()
await db.collection('users')
.where({_openid: 'user-open-id'})
.get({success: function(res) {console.log(res.data)
}
})
正文完