890 B
890 B
云数据库
首先第一步,需要初始化云服务器
你需要拿到你的环境ID,接下来需要在 app.js 中做初始化工作
App({
onLaunch() {
// 初始化云服务
wx.cloud.init({
env: 'cloud1-5gsobkys7eb1b3ef'
});
},
})
初始化完毕后,我们就可以使用云服务了(云数据库、云存储、云函数)
下面是在云数据库中增加数据的示例:
// 获取云端的数据库实例
const db = wx.cloud.database();
首先获取云端数据库的实例,接下来通过数据库实例获取集合
// 再从数据库中获取到集合(表)
const students = db.collection('students');
通过集合调用相应的方法来进行增删改查,例如要增加一条记录,那就是调用 add 方法
students.add({
data : this.data
}).then(res=>{
console.log(res)
})