Related Process for Invoking Cloud Functions in the WeDa Application
This document primarily introduces four processes for invoking cloud functions in WeDa.
Cloud Function Connector Triggering
-
Create a new Cloud Development Connector in Cloud Development Platform - APIs - Open Services

-
Create a new Cloud Development Connector query in the visual editor

-
Select the Cloud Development Connector created in Step 1

Invoking APIs-Cloud Function Triggering
-
In Cloud Development Platform-APIs, create a new method and select the type as Cloud Function

-
In the visual editor, configure events and invoke the data source method.

-
In the data source method configuration panel, select the APIs method created in the previous step.

JavaScript Method Triggering
- Go to the application editor, where you can call cloud functions in custom js methods and invoke them in component and page lifecycles. For code examples, refer to Using and Managing APIs

export default async function ({ event, data }) {
const result = await $w.cloud.callDataSource({
dataSourceName: "custom API identifier",
methodName: "method identifier",
params: {}, // method input parameters
});
}
or
export default async function ({ event, data }) {
const result = await $w.cloud.callFunction({
dataSourceName: "custom API identifier",
methodName: "method identifier",
params: {}, // method input parameters
});
}
-
$w.cloud.callFunction. For details, refer to Cloud Invocation Methods
-
Calling a cloud function requires executing an asynchronous method.
Trigger by query
-
Create a new cloud function query query in the editor

-
The query code is as follows

-
Call query

Quick Triggering in Mini Programs
The above triggering methods are applicable in mini programs. Additionally, wx.cloud.callFunction is an important API in WeChat Mini Program cloud development for invoking cloud functions. Through it, cloud functions defined in the cloud development environment can also be triggered on the mini program side.
The wx.cloud.callFunction method requires a mini-program environment.