Detailed Explanation of WeChat Mini Program Cloud Development

Understanding Mini Program Cloud Development

  1. Small program cloud development is a professional small program development service launched by the WeChat team and Tencent Cloud.
  2. Developers can use cloud development to quickly develop small programs, small games, official account pages, etc., and open up WeChat's open capabilities natively.
  3. Developers do not need to build a server, and can directly use the API provided by the platform for business development without authentication.
  4. Cloud development provides three basic capabilities to help developers quickly develop small programs:

Cloud functions: Developers can write functions according to business needs and deploy them on the cloud, which can be called in applets. Developers do not need to maintain complex authentication mechanisms, nor do they need to purchase or build servers, and can easily complete the development of small programs.
Database: Developers can directly read and write to the database in the front end of the applet or in the cloud function, and support data management through the cloud console in the developer tool.
Storage management: Developers can easily and quickly implement file upload/download and management functions on the front end of the applet, and can also manage them in the developer tool "Cloud Development" console.

Preparing for cloud development

1. Create a cloud development applet
insert image description here

2. Enter the applet page and click to enter cloud development
insert image description here
3. Create a cloud development database
insert image description here
4. Add some records
insert image description here

Create a cloud function

insert image description hereinsert image description here
After creating the file, you need to click cloudfunction
to select the current environment
insert image description here

Definition of Cloud Function

// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
    
     env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境
// 拿到数据库
const db=cloud.database();
// 云函数入口函数
exports.main = async (event, context) => {
    
    
  const wxContext = cloud.getWXContext()

Call the cloud function in the page: wx.cloud.callFunction

sendFeed() {
    
    
    console.log("发表留言");
    // 执行函数
    wx.cloud.callFunction({
    
    
        name: "addFeed",
        data: {
    
    
          msg: this.data.msg, //留言信息
          userInfo: wx.getStorageSync('userInfo'), //用户信息
        }
      })

How to operate cloud data in cloud functions
1. Initialization: var db = cloud.database();
2. Acquisition: var data = await db.collection(“feedback”).get()
3. Add: var data = await db .collection(“feedback”).add(data:{add data})

Guess you like

Origin blog.csdn.net/ck2018182068/article/details/127914825