Skip to main content

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

  1. Create a new Cloud Development Connector in Cloud Development Platform - APIs - Open Services alt text

  2. Create a new Cloud Development Connector query in the visual editor alt text

  3. Select the Cloud Development Connector created in Step 1 alt text

Invoking APIs-Cloud Function Triggering

  1. In Cloud Development Platform-APIs, create a new method and select the type as Cloud Function alt text

  2. In the visual editor, configure events and invoke the data source method. alt text

  3. In the data source method configuration panel, select the APIs method created in the previous step. alt text

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
});
}
Note
  • $w.cloud.callFunction. For details, refer to Cloud Invocation Methods

  • Calling a cloud function requires executing an asynchronous method.

Trigger by query

  1. Create a new cloud function query query in the editor

  2. The query code is as follows

  3. 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.

tip

The wx.cloud.callFunction method requires a mini-program environment.