API List
Namespace `$w
WeDa uses $w
as a unified scope reference and namespace. All capabilities of the WeDa front-end runtime can be accessed through this namespace. Typical usages include:
Front-end instance access, such as:
- Component instance access: $w.<COMPONENT_ID>, such as
$w.input1.value
,$w.input1.setValue("Hello Weda!")
- Data query instance access: $w.<QUERY_ID>, such as
$w.query1.data
- Event flow instance access: $w.<EVENT_FLOW_ID>, such as
$w.eventflow1.trigger()
- Component instance access: $w.<COMPONENT_ID>, such as
Platform methods/properties access, such as:
// Function expression
$w.ABS(1)
// User permissions
$w.auth.currentUser
// Invoke cloud capabilities such as data sources
$w.cloud.callDataSource({ ... })
// Tool Methods
$w.utils.showLoading()
// Access the current page or app instance
$w.app.id // Get the application ID
$w.page.dataset.params.query1 // Get current page parametersAccess to data and index (item/index) in loop scope:
$w.index_<postfix>, $w.item_<postfix>
The platform properties and methods include:
Name | Type | Description |
---|---|---|
app | object | Current application instance |
page | object | Current page instance |
auth | object | User permission related methods and properties |
device | object | Current device information |
env | object | Current environment information |
wedaContext | object | Current context information |
cloud | object | Collection of data sources and other cloud capabilities |
ai | object | AI+ capabilities |
utils | object | Collection of platform utility methods |
<function-expression-name> | function | Collection of function methods provided by the platform |
Instance Access
Universal access to various instances within WeDa is available through the unified namespace $w. When instance identifiers are identical, instances in the page scope take precedence. Within the same scope, access follows the priority order of data queries, event flows, and components.
Component Instance
Using the component ID $w.<COMPONENT_ID>
allows direct component referencing, such as $w.button1
and $w.form1
. Component references enable access to read-only properties and method invocation, for example, $w.listView1.refresh()
refreshes the data list component with id
listView1, while $w.button1.text
directly retrieves the text content of the button1 component.
Note that if a component is within a loop repeater
, its reference cannot be directly accessed outside that repeater
. However, other components within the same repeater
can still reference sibling components or components outside the repeater using $w.<COMPONENT_ID>
.
Common Properties/Methods
WeDa components possess certain properties and methods. The following properties and methods are common to all components:
Name | Type | Description |
---|---|---|
id | string | Component ID, usually generated by the editor in WeDa |
component | string | Component name, such as WdButton |
module | string | Component library name, the default in WeDa is gsd-h5-react |
parent | Component | Parent component reference |
children | Component[] | Collection of child components |
For more component documentation, please refer to the specific Component Documentation.
**In WeDa applications, do not use separate variables to store reference-type properties (objects, methods, etc.) of components and then use those variables directly**
// Bad
const mySetValue = input1.setValue;
mySetValue("xxx");
Because in WeDa, the same component's properties and methods are not always the same reference at different times, such as the setValue method of form components. Whether a specific property will change depends on the component's implementation, and the reason for this is related to WeDa's default react implementation on the web.
Loop Display Component
The loop display component repeater
is a special type of component in WeDa. Its internal components will have multiple instances created at runtime, exhibiting some scope-like effects during usage:
- Instances inside the loop cannot be directly referenced from outside the loop.
- Within the loop,
$w.item_xxx
and$w.index_xxx
scoped context references will be created. Components inside the loop display component can access the current item's data, index, or component instances within the same item via$w.<api>
. Details are as follows:
Name | Type | Description |
---|---|---|
item_<postfix> | any | The data of the current loop item. The data type depends on your loop data, e.g., [{name: 'Sarah'}], which is an object. |
index_<postfix> | number | The index of the current loop item |
<COMPONENT_ID> | string | Accesses component instances within the same item by component ID |
For more documentation on how to use the loop display component, please refer to the Loop Display Component Usage Documentation.
There are components that encapsulate loops, such as tables, which exhibit similar scoped behavior.
Data Query (query)
Data query instance is an object-oriented encapsulation of data requests, supporting automatic triggering by monitoring request parameters / manual triggering via methods. The instance contains data and error properties that record the response results of the last data request.
Using the data query identifier ($w.<QUREY_ID>
), you can access the defined data query instance, such as $w.query1
. By obtaining the data query instance, you can access the latest query data $w.query1.data
, or call instance methods like $w.query1.trigger()
to trigger the query for the current instance.
Properties and Methods
Name | Type | Description |
---|---|---|
id | string | The data query identifier. It must be unique within the page, and globally it should not duplicate any other query identifier. |
data | any | The response result when the data request is successful. Default: null |
error | error | Error object when the data request fails. Default: null |
isFetching | boolean | Indicates whether the data request is in progress. Default: false |
trigger | function | Triggers a data request based on the set parameters. Type: (params={}) => any. The params can be accessed in the query via the binding expression 'params'. |
reset | function | Resets data and error to null |
Runtime Constraints
- Scope, includes global/page scope:
- Global queries can be accessed from any scope. Within a query (e.g., data request parameter binding), only global data can be accessed (Note: $w.page is a page-level object and thus inaccessible).
- Page queries can only be accessed by objects within the page. Since page variables initialize earlier, query values should not be accessed in page variable initialization methods. Within a page query, global data and static page object data (e.g., $w.page.id, $w.page.dataset.xxx) can be accessed, but not component instances (e.g., $w.button1), loop scopes (e.g., $w.item_xxx), or other lower-level scope values.
- When triggering a query, additional data can be passed using methods like
query.trigger({test:10})
. In the query configuration, the passed data (10
) can be accessed via the binding expressionparams.test
. When a query is triggered automatically,params
will get{}
.
- Lifecycle
- Creation: The query is created synchronously when the app or page instance is created.
- Initialization: For automatically triggered queries (where trigger is "auto"), initialization occurs after variable initialization completes but before the app/page Load lifecycle. This means app/page variables can be used in the query initialization method. Unlike variables, query initialization uses a fully asynchronous manner and does not block any operations.
- Destruction: The query instance is destroyed along with the app/page instance when it is destroyed.
Event Flow (EventFlow)
On WeDa components, you can configure a series of responses to component events. Corresponding handling methods can be further configured based on the success or failure events of the response functions. Event Flow encapsulates this event orchestration approach by packaging a series of actions chained by events into a single unit, reusable within the page. Unlike process engines, Event Flow executes locally on the client side, while processes run on backend servers.
Properties and Methods
Name | Type | Description |
---|---|---|
id | String | Event Flow identifier, which must be unique within the page |
trigger | Function | Triggers the event flow via the event (${id}.start). Type: (data) => any. The data can be obtained in the entry node of the event flow via event.detail |
Runtime Constraints
- Ordinary event orchestration re-triggers success or failure events based on each response action. For a single event, multiple parallel response functions can be configured, ultimately forming a tree with multiple leaf nodes. Unlike ordinary event orchestration, Event Flow is triggered externally as a unified response action, requiring a unique exit state; thus, only one response action can be configured per event, and concurrent multiple actions are not supported.
- Scope: The configuration of each response action can only access event data, global data, and static data of page objects (meaning it excludes component scope, loop scope, etc.). The entry node can obtain data passed when triggering the event flow via
event.detail
.
Application Instance
The WeDa frontend application instance can be accessed via $w.app
, and $app
can also be used as a shortcut reference.
$w.app
Name | Type | Description |
---|---|---|
id | string | Application id |
label | string | Application name |
version | string | Application version |
mpAppId | string | Mini Program appid |
mpAppName | string | Mini Program name |
dataset | AppDataset | Global data object |
common | object | Global common methods |
setState | function | Sets global variables |
Page Instance
The current page instance is accessed via $w.page
and can be quickly referenced using $page
.
$w.page
Name | Type | Description |
---|---|---|
id | string | Current page's id |
label | string | Current page's name |
path | string | Current page's path |
dataset | PageDataset | Page data object |
handler | object | Page-defined handler method |
setState | function | Sets page variables |
setParams | function | Replaces page parameters |
Device Information
Current device information is accessed via $w.device
.
$w.device
Name | Type | Description |
---|---|---|
viewport | object | Viewport information |
networkType | string | Mobile network type |
Environment Information
Current environment information is accessed via $w.env
.
$w.env
Name | Type | Description |
---|---|---|
type | string | Environment type |
id | string | Environment ID |
Context Information
Current context information is accessed via $w.wedaContext
.
$w.wedaContext
Name | Type | Description |
---|---|---|
isEditorMode | boolean | Whether in the editor area |
platforms | array | Application runtime terminals ['WEB', 'MOBILEWEB', 'PCWEB', 'MOBILE', 'MP'] |
Platform Methods
WeDa provides a series of built-in front-end methods that can be called in the front end.
User/Permissions
Name | Description |
---|---|
$w.auth.getUserInfo | Gets user information |
$w.auth.currentUser | User information reference |
$w.auth.signOut | Signs out user |
$w.auth.loginScope | Gets user login scope |
Data Source
Name | Description |
---|---|
$w.cloud.callDataSource | Calls data source |
AI
Name | Description |
---|---|
$w.ai.LLM.chat | Chats with large language models (LLMs), supporting both streaming and non-streaming conversations. |
$w.ai.bot.sendMessage | Conducts streaming dialogue with Agent, returning text streams and SSE event streams. |
$w.ai.bot.getRecommendQuestions | Gets Agent-recommended problem suggestions, returning text streams and SSE event streams |
$w.ai.bot.get | Gets information about a specific Agent |
$w.ai.bot.list | Bulk gets information for multiple Agents |
$w.ai.bot.getChatRecords | Gets chat records |
$w.ai.bot.sendFeedback | Sends feedback for a specific chat record |
$w.ai.bot.getFeedback | Gets existing feedback information |
$w.ai.bot.createConversation | Creates a new conversation with an Agent |
$w.ai.bot.getConversation | Gets the conversation list |
$w.ai.bot.deleteConversation | Deletes the specified conversation |
$w.ai.bot.speechToText | Speech to Text |
$w.ai.bot.textToSpeech | Text to Speech |
$w.ai.bot.getTextToSpeechResult | Gets the text-to-speech result |
Process
Name | Description |
---|---|
$w.cloud.callWorkflow | Calls workflow |
Other Cloud Capabilities
Name | Description |
---|---|
$w.cloud.getTempFileURL | Gets the http access URL for static files via cloudid |
$w.cloud.getCloudInstance | Returns the initialized CloudBase web-sdk instance (without having to manage tcb environment information or authentication/login handling), i.e., the object returned after tcb.init, which can be used to directly call various tcb capabilities |
$w.cloud.callFunction | Calls CloudBase cloud functions, with an effect largely consistent with the $w.cloud.getCloudInstance example |
$w.cloud.getUrlWithOpenidToken | In the login authentication source settings, after enabling "WeChat Mini Program OPENID Login" for H5, this function returns an H5 redirect link containing the WeChat Mini Program authorization token parameter. This link can be used for silent OpenID authorization login in H5 pages within the WeChat Mini Program webview. |
General Tools/Interaction Methods
Name | Description |
---|---|
$w.utils.showToast | Display a toast |
$w.utils.showLoading | Displays a global loading indicator |
$w.utils.hideLoading | Hides the global loading indicator |
$w.utils.showModal | Display a modal dialog |
$w.utils.callPhone | Makes a phone call |
$w.utils.scanCode | Scan a QR code |
$w.utils.setClipboardData | Copy to clipboard |
$w.utils.navigateTo | Navigate to a specific page in the app |
$w.utils.redirectTo | Close the current page and navigate to a page within the app |
$w.utils.reLaunch | Close all pages and open a specific page within the app |
$w.utils.relaunchHome | Return to the home page |
$w.utils.navigateBack | Close the current page and go back to the previous page or multiple pages |
$w.utils.getEnumValue | Gets the enumeration value |
$w.utils.getStorage | Gets cached data |
$w.utils.setStorage | Stores data in the local cache under the specified key |
$w.utils.removeStorage | Removes the specified key from the local cache |
$w.utils.exportData WEB | Export data to a file |
$w.utils.requestSubscribeMessage Mini Program | Invokes the client-side mini program's subscription message interface and returns the user's subscription operation result |
$w.utils.openLocation Mini Program | View a location using the WeChat built-in map |
$w.utils.reserveChannelsLive Mini Program | Reserves Channels live |
$w.utils.openchannelsUserProfile Mini Program | Open Channels Profile |
$w.utils.openChannelsLive Mini Program | Opens Channels live |
$w.utils.openChannelsEvent Mini Program | Opens Channels event page |
$w.utils.openChannelsActivity Mini Program | Opens Channels video |
$w.utils.getChannelsLiveNoticeInfo Mini Program | Gets Channels live notice information |
$w.utils.getChannelsLiveInfo Mini Program | Gets Channels live information |
Function expression
Function expressions are a set of static logical utility methods primarily used for processing and transforming various data within applications. In the component property binding expression area, the $w
prefix can be omitted.
Name | Description |
---|---|
$w.ABS | Calculates the absolute value of the input number. |
$w.Min | Returns the minimum value in a set of numbers. |
$w.Max | Returns the maximum value in a set of numbers. |
$w.Average | Returns the average value in a set of numbers. |
$w.Sum | Calculates the sum of a set of numbers. |
$w.Floor | Returns the floor of the input number. |
$w.Ceiling | Returns the ceiling of the input number. |
$w.Round | Returns the input number rounded to the nearest integer. |
$w.Rand | Returns a pseudo-random integer within a specified range. |
$w.If | Performs a logical comparison based on specified conditions, returning one value when conditions are met and another when they are not. |
$w.IsEmpty | Determines whether the input value is empty; if the result is an array type, it also checks whether all items in the result array are empty. |
$w.And | Used to determine whether all conditions are true. |
$w.Or | Returns true if any condition is true; returns false only when all conditions are false. |
$w.DateText | Formats a date and time into text of a specified format. |
$w.DateTimeValue | Converts date-time text to a datetime according to the specified format. |
$w.Now | Returns the current system time, typically used in combination with other date-time functions. |
$w.GetDate | Returns a date value based on the input year, month, and day values. |
$w.Timestamp | Returns a timestamp based on the input date and time. |
$w.Second | Returns the seconds based on the input date and time. |
$w.Minute | Returns the minutes based on the input date and time. |
$w.Hour | Returns the hour (in 24-hour format) from the input date and time. |
$w.Day | Returns the day (1-31) from the input date and time. |
$w.DayOfWeek | Returns the day of the week based on the input date and time. |
$w.Month | Returns the month from the input date and time. |
$w.Year | Returns the year from the input date and time. |
$w.Age | Calculates the age based on two input date and time values. |
$w.AgeOfNow | Calculates the current age. |
$w.DateAdd | Adds X days to the input date and time (supports negative values). |
$w.MonthAdd | Adds X months to the input date and time (supports negative values). |
$w.YearAdd | Adds X years to the input date and time (supports negative values). |
$w.YearDiff | Returns the difference in years between two date-time fields (zero if in the same year). |
$w.MonthDiff | Returns the difference in months between two date-time fields (zero if in the same month). |
$w.DateDiff | Returns the difference in days between two date-time fields (zero if on the same day). |
$w.HourDiff | Returns the difference in hours between two date-time fields (zero if in the same hour). |
$w.MinuteDiff | Returns the difference in minutes between two date-time fields (zero if in the same minute). |
$w.SecondDiff | Returns the difference in seconds between two date-time fields (zero if in the same second). |
$w.IsToday | Determines whether the passed date and time is today. |
$w.TimeText | Formats time into text of a specified format. |
$w.Len | Gets the character count of the input text. |
$w.Contains | Determines whether text 1 contains text 2. |
$w.Split | Splits text 1 into a text array based on the input text 2 |
$w.Trim | Removes all spaces and tabs at the beginning and end of the text, while preserving those in the middle. |
$w.Upper | Converts the input text to uppercase. |
$w.Lower | Converts the input text to lowercase. |
$w.Concat | Returns a new text string by concatenating multiple input texts. |