小程序云函数调用出现的问题,如何解决?
发布于 8 年前 作者 pingyin 9854 次浏览 来自 官方Issues

调用代码如 下:add.js

wx.cloud.init()

Page({

  /**

   * 页面的初始数据

   */

  data: {

  },

  addData:function(event){

    wx.cloud.callFunction({

        name: ‘addData’

      }).then(res => {

         console.log(res)

        })

  }

})

出现的报错如下:

VM42 WAService.js:1 Uncaught (in promise) Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID , cloud function service error code -501000, error message Environment not found; at cloud.callFunction api;

    at new u (VM42 WAService.js:1)

    at d (VM42 WAService.js:1)

    at f (VM42 WAService.js:1)

    at Function.success (VM42 WAService.js:1)

    at VM42 WAService.js:1

    at C (VM42 WAService.js:1)

    at i.<anonymous> (VM42 WAService.js:1)

    at i.emit (VM42 WAService.js:1)

    at Yi (VM42 WAService.js:1)

    at VM42 WAService.js:1

云函数文件:index.js

// 云函数入口文件

const cloud = require(‘wx-server-sdk’)

cloud.init()

const db = wx.cloud.database()

const productsCollection = db.collection(‘products’)

// 云函数入口函数

exports.main = async (event, context) => {

  return await productsCollection.add({

    data:{

      titile: “product 1”,

      image: ‘https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg’,

      tags: [“tga1”, “tag2”],

      price: 120.12,

      color: ‘red’

    }

  })

 

}

2 回复

cloud.init的时候把环境ID传参

解决了吗朋友,我也遇到这个问题

回到顶部