Common error reporting problems
Just create cloud development to report a mistake, is really small mouth wipe honey.
- You can buy the free version in the developer tools, but all of a sudden, my editor is going crazy and I’m reporting errors all the time.
Error: Base resp abnormal, {"ret":1000,"errmsg":""}
- It needs to be purchased in the cloud development column of wechat public platform
Cloud development creation process
General knowledge
- Enable cloud development or an error will be reported
How do I obtain openID
- To obtain the openID, enable the cloud function
To upload pictures
- You need to configure the environment ID to upload images. Otherwise, the images will be uploaded to the first environment by default when multiple cloud services are deployed.
- Configure the environment ID in the app.js file
App({
onLaunch: function () {
if(! wx.cloud) {console.error('Please use base library 2.2.3 or above to use cloud capabilities')}else {
wx.cloud.init({
// env
The // env argument determines which cloud environment resources will be requested by default by the next cloud development call (wx.cloud.xxx) made by the applet
// Enter the environment ID. You can view the environment ID on the cloud console
// If not, use the default environment (the environment created first).
env: 'my-env-id'## Open commentstraceUser: true})},this.globalData = {}
}
})
Copy the code
- On the cloud server, you can create folders and upload files to the folders easily. Just request the path plus the file name of the folder
// Upload the image
const cloudPath = `image/my-image${filePath.match(/ \ [^.] +? $/) [0]}`
Copy the code
Front-end operational database
- Create database
- Open the pages/databaseGuide databaseGuide js file, find the corresponding database operation method
- Uncomment commented code
- For example, the onAdd method adds a new JSON record to the counters set in the following format.
im
- And front-end operation database is the same, just need to create a database to play.
Cloud function creation
- Right-click the root directory of cloudfunctions, cloudfunctions, and choose new cloudfunction. Name it sum
- In creating cloudfunctions/sum/index. Js file add the following code
// Cloud function entry function
exports.main = async (event, context) => {
console.log(event)
console.log(context)
return {
sum: event.a + event.b + 3}}Copy the code
- If a cloud function is created, even after the code is written. But the code does not take effect if it is not uploaded to a cloud server
- Right click on the cloud function to deploy it to the cloud service.
Cloud call
- To develop data calls and obtain user sensitive data, cloud functions can be used only after being uploaded to the cloud.
- All cloud functions need to be uploaded to the cloud and called to enable the corresponding cloud service.
- The cloud function is to get the environment ID, so we write the cloud function, need to add this paragraph. The modified code must be uploaded to the cloud server or an error will be reported.
cloud.init({
// The API calls are kept consistent with the current environment of the cloud function
env: cloud.DYNAMIC_CURRENT_ENV
})
Copy the code