In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how Mini Program cloud development calls the interface". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought. Let's study and learn "Mini Program Cloud development how to call the interface"!
The following is for you to understand how to do Mini Program Cloud development?
Activate cloud development
After creating the first cloud development Mini Program, you need to activate cloud development before using cloud development capabilities. On the left side of the developer tools toolbar, click the "Cloud Development" button to activate cloud development. After cloud development is launched, a set of cloud development environment is automatically obtained. Each environment is isolated from each other, and each environment contains independent database instances, storage space, cloud function configuration and other resources. Each environment has a unique environment ID identity, and the initially created environment automatically becomes the default environment.
Cloud development console
The Cloud Development console is the place to manage cloud development resources. The console provides the following capabilities:
Overview: view cloud development infrastructure usage data
User management: viewing Mini Program user information
Database: manage database, view, add, update, find, delete data, manage indexes, manage database access, etc.
Storage management: viewing and managing storage SPAC
Cloud functions: view the list, configuration, logs and monitoring of cloud functions
Statistical analysis: view specific usage statistics of cloud development resources
Resources and environment
An environment corresponds to a set of independent cloud development resources, including databases, storage space, cloud functions, and so on. Each environment is independent of each other. Users have a maximum of two environments by default after activating cloud development. In the actual development, it is recommended that each formal environment should be equipped with a test environment, and all functions should be tested in the test environment before going to the formal environment. Taking the two environments that can be created initially as an example, it is recommended that one be created as a test test environment and the other as a formal release environment.
The following is the whole process of how Mini Program Cloud developer calls the API:
The first step is to upgrade a version of the developer's tools, updated to the latest, download address: https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html
1. After downloading to the latest tool, open it, and first create a folder named functions to store our own cloud functions.
2. Find the project.config.json file and add "cloudfunctionRoot": "functions/" to configure our cloud function directory.
{"description": "Project profile." , "cloudfunctionRoot": "functions/", "setting": {"urlCheck": true, "es6": true, "postcss": true, "minified": true, "newFeature": true}, "compileType": "miniprogram", "libVersion": "2.1.3", "appid": "asdaaaaaa", "projectname": "", "condition": {"search": {"current":-1, "list": []}, "conversation": {"current":-1 "list": []}, "plugin": {"current":-1, "list": []}, "game": {"current":-1, "list": []}, "miniprogram": {"current":-1, "list": []}} 3. Find whether the directory of cloud function is unique. If yes, right-click: create a new node.js cloud function. At this time, the system will configure a basic version of the cloud function to us, and we will take this basic cloud function to go through a process.
/ / Cloud function entry file const cloud = require ('wx-server-sdk') cloud.init () / / initialization. Before Mini Program calls the function, you must first call the initialization / / cloud function entry function exports.main = async (event, context) = > {return {sum: event.a + event.b,//event contains data passed by some users. Parameter an and parameter buserInfo: event.userInfo / / can also obtain the user's openid directly. These are given by Tencent and do not need to be authorized by the user, which is very secure. }} 4. In our functions directory, right-click our add, select: upload and deploy, and then call:
Wx.cloud.callFunction ({name: 'add',data: {a: 1 res b: 9}) .then ((res) = > {console.log (res)}) 5. Are you excited? if you follow the official document, you may encounter the following problems:
Problem ①: it is easy to solve this problem in Cannot read property 'callFunction' of undefined;. This problem is usually due to the low version of the debug base library, which can be adjusted upwards. Problem ②: another problem was found after finding that the version library had been upgraded
ErrCode:-1 | errMsg: Cloud API isn't enabled, please call wx.cloud.init first
Call wx.cloud.init () to complete initialization before calling other cloud API. The init method can be passed in an object to set the default configuration, as detailed in the documentation. ; at pages/test/test page getData function
Error: errCode:-1 | errMsg: Cloud API isn't enabled, please call wx.cloud.init first
Call wx.cloud.init () to complete initialization before calling other cloud API. The init method can be passed in an object to set the default configuration, as detailed in the documentation.
This problem is that it needs to be initialized before calling the cloud function. Wx.cloud.init () is fine. Then call the cloud function.
Successfully obtained the returned data. Even if an initial simple small demo provided by the government is available, the rest are basically such operations, but special operations need to be performed against the official database operations.
Thank you for your reading. The above is the content of "how Mini Program Cloud developers call APIs". After the study of this article, I believe you have a deeper understanding of how Mini Program Cloud developers call APIs. The specific usage still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.