1. 报错信息:
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。
2. 代码
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.项目目录
4. 云函数控制台报错
需要先调用 cloud.init()
微信小程序的启动页面问题:
在app.json里面第一项是pages/home/home,第三项是pages/index/index,在提交的体验版中,每次小程序打开出现的页面是home页面,但是审核发布后,每次打开小程序都是index页面,请问这是为什么?