WeChat applet cloud development (11) - "How to use cloud functions"

How to use cloud functions?

We use cloud functions to connect to the database as a demonstration


1. Write cloud functions

1. Write the database connection code in the entry function

cloud.database().collection('goods').get()

insert image description here

  • Note: The code we used to request the database directly in the js file of the page is in
    insert image description here
    front ofwx.
    (In applet development, wx. represents local, we must omit it in cloud functions!)

2. Call the cloud function

1. We create a new "yunhanshu" page under Page
insert image description here
2. Call the getData cloud function in yunhanshu.js

Page({
    
    
  onLoad(){
    
    
    //云函数调用
    wx.cloud.callFunction({
    
    
      name:'getData'
      })
  }
)}

insert image description here
3. Save and compile, and check the console information
insert image description here
. The call is successful!

Guess you like

Origin blog.csdn.net/qq_47354826/article/details/119549669