关于node.js:小程序云开发入门

7次阅读

共计 543 个字符,预计需要花费 2 分钟才能阅读完成。

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