1、云函数 name
const cloud = require('wx-server-sdk')
wx.cloud.init({
env: "xxxxxx"
})
const db = cloud.database()
exports.main = async (event, context) => {
try {
return await db.collection('gxser').doc('a85ed387c100134853').get()
}
catch (err) {
console.log(err)
}
}
2、pages中的index.js
Page({
onAdd:function() {
wx.cloud.callFunction({
name: "name",
success(res) {
console.log("请求成功", res)
},
fail(res) {
console.log("请求失败", res)
}
})
}
})
3、index.wxml
<button bindtap="onAdd">用函数</button>
--------------------------------------------------------------------------------------------
运行提示:
请求失败 Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID b5007aac-a98c-11ea-922e-5254001dad8e, cloud function service error code -504002, error message wx is not defined; at cloud.callFunction api;
at new u (VM319 WAService.js:2)
at d (VM319 WAService.js:2)
at f (VM319 WAService.js:2)
at Function.success (VM319 WAService.js:2)
at VM319 WAService.js:2
at T (VM319 WAService.js:2)
at i.<anonymous> (VM319 WAService.js:2)
at i.emit (VM319 WAService.js:2)
at Si (VM319 WAService.js:2)
at VM319 WAService.js:2
集合权限修改了吗