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()
- Note: The code we used to request the database directly in the js file of the page is in
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
2. Call the getData cloud function in yunhanshu.js
Page({
onLoad(){
//云函数调用
wx.cloud.callFunction({
name:'getData'
})
}
)}
3. Save and compile, and check the console information
. The call is successful!