收藏
回答

小程序自定义组建中如何使用云开发数据库?

现在自定义组建中使用云开发的数据库,但是报错:

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");
    },

  }
})
最后一次编辑于  2020-02-28
回答关注问题邀请回答
收藏

1 个回答

  • Mr.Zhao
    Mr.Zhao
    2020-02-27
    const db = wx.cloud.database();
    
    2020-02-27
    有用
    回复 3
    • SKY
      SKY
      2020-02-28
      第二行我就有这段代码了。
      2020-02-28
      回复
    • Mr.Zhao
      Mr.Zhao
      2020-02-28回复SKY
      你太不认真了,仔细比对下吧,多说无益
      2020-02-28
      回复
    • SKY
      SKY
      2020-02-28回复Mr.Zhao
      是我粗心了。。。
      2020-02-28
      回复
登录 后发表内容
问题标签