1.开通云开发
2.project.config.json。文件中加入配置 , "cloudfunctionRoot": "cloudFuction/",
{
"description": "项目配置文件",
"cloudfunctionRoot": "cloudFuction/",
...
3.根目录下创建 cloudFuction 文件夹
4.安装node js 。创建云函数。
5.在云函数根目录 cmd 下 执行 npm install --save wx-server-sdk@latest
6.上传部署
7.在App.js 初始化 wx.cloud.init();
8.调用测试
wx.cloud.callFunction({
// 云函数名称
name: 'grammarData',
// 传给云函数的参数
data:null,
success: function (res) {
console.log("云函数success");
console.log(res);
},
fail: function (res){
console.log("云函数fail");
console.log(res);
}
})
参考