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 CloudBase Connector in CloudBase Platform - APIs - Open Services alt text

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

  3. Select the CloudBase Connector created in Step 1 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 CloudBase for invoking cloud functions. Through it, cloud functions defined in the CloudBase environment can also be triggered on the mini program side.

tip

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