微信开发者工具调用云函数失败,提示没有完成云函数初始化?
- 报错信息:
index.js:118 Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail cloud function service error code -504002, error message errCode: -1 unknown error | errMsg: Cloud API isn’t enabled, please call init first
请先调用 init 完成初始化后再调用其他云 API。
- 代码
addToDB: function () { var newData = this .data; var statusText = '' ; if (newData.status === 'radio1' ) { statusText = '装车送出' ; } else { statusText = '卸车送达' ; } console.log( "准备调用云函数" ); wx.cloud.callFunction({ name: 'db' , data: { type: 'add' , carNumber: newData.carNumber, driver: newData.driver, phoneNumber: newData.phoneNumber, distribute: newData.distribute, destination: newData.destination, thingsName: newData.thingsName, manufModel: newData.manufModel, number: newData.number, status: statusText, saveType: 'formData' }, success: function (res) { wx.showToast({ title: '保存成功' , }); setTimeout( function () { wx.navigateTo({ url: '../table/table' }); }, 1000); }, fail: function (err) { console.log(err); console.log( '保存失败' ); } }) }, uploadData: function () { var form = this .data; if (!form.carNumber || !form.driver) { wx.showToast({ title: '表单不能为空' , icon: 'none' }); return ; } console.log(form); this .addToDB(); } |
3.项目目录
- 云函数控制台报错