小程序自定义组建中如何使用云开发数据库?
现在自定义组建中使用云开发的数据库,但是报错:
thirdScriptError
db.collection is not a function; [Component] Lifetime Method Error @ utils/components/banner/banner#attached
TypeError: db.collection is not a function
代码如下:
wx.cloud.init();
const db = wx.cloud.database //Init cloud database
Component({
lifetimes: {
attached: function() {
this.getBanners();
}
},
properties: {
},
/**
* Component initial data
*/
data: {
},
/**
* Component methods
*/
methods: {
getBanners: function() {
db.collection('bannerImages').doc('55577acd-7d00-4474-bdf9-872a0a8b646a').get().then(res => {
console.log(res.data)
})
console.log("getting banners");
},
}
})