前端随心记---------小程序的云函数

小程序的云函数开发:

 

 

开启小程序的云开发模式:

当每次添加新的函数时,都需要手动进行上传,需支持npm时要在项目开启nom支持。

云函数的增删改查:

增:

insert: function () {
    db.collection('user').add({
      data: {
        name: 'may',
        age: 18
      },
      success: res => {
        console.log(res);
      },
      fail: err => {
        console.log(err);
      }
    })
  },

改:

  updata:function(){
    db.collection('user').doc('137264b55db292b30067d7b716f48bd9').update({
      data:{
        age:21
      }
    }).then(res => {
      console.log(res)
    }).catch(err => {
      console.log(err);
    })

  },

查:

search:function(){
    db.collection('user').where({
      age:21

    }).get().then(res => {
      console.log(res);
    }).catch(err =>{
      console.log(err);
    });
  },

删:

 delete:function(){
    db.collection('user').doc('137264b55db292b30067d7b716f48bd9').remove().then(res =>{
      console.log(res);
    }).catch(err =>{
      console.log(err);
    })
  },

求和:

 sum:function(){
    wx.cloud.callFunction({
      name:'sum',   云函数名
      data:{
        a:2,
        b:3
      }
    }).then(res => {
      console.log(res)
    }).catch(err => {
      console.log(err)
    })
  },

 

猜你喜欢

转载自www.cnblogs.com/hudunyu/p/11746891.html
今日推荐