Skip to main content

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()
  • 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 parameters
  • Access to data and index (item/index) in loop scope: $w.index_<postfix>, $w.item_<postfix>

The platform properties and methods include:

NameTypeDescription
appobjectCurrent application instance
pageobjectCurrent page instance
authobjectUser permission related methods and properties
deviceobjectCurrent device information
envobjectCurrent environment information
wedaContextobjectCurrent context information
cloudobjectCollection of data sources and other cloud capabilities
aiobjectAI+ capabilities
utilsobjectCollection of platform utility methods
<function-expression-name>functionCollection 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:

NameTypeDescription
idstringComponent ID, usually generated by the editor in WeDa
componentstringComponent name, such as WdButton
modulestringComponent library name, the default in WeDa is gsd-h5-react
parentComponentParent component reference
childrenComponent[]Collection of child components

For more component documentation, please refer to the specific Component Documentation.

Do not store component reference properties unnecessarily.

**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:

  1. Instances inside the loop cannot be directly referenced from outside the loop.
  2. 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:
NameTypeDescription
item_<postfix>anyThe data of the current loop item. The data type depends on your loop data, e.g., [{name: 'Sarah'}], which is an object.
index_<postfix>numberThe index of the current loop item
<COMPONENT_ID>stringAccesses 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

NameTypeDescription
idstringThe data query identifier. It must be unique within the page, and globally it should not duplicate any other query identifier.
dataanyThe response result when the data request is successful. Default: null
errorerrorError object when the data request fails. Default: null
isFetchingbooleanIndicates whether the data request is in progress. Default: false
triggerfunctionTriggers a data request based on the set parameters. Type: (params={}) => any. The params can be accessed in the query via the binding expression 'params'.
resetfunctionResets data and error to null

Runtime Constraints

  1. 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 expression params.test. When a query is triggered automatically, params will get {}.
  2. 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

NameTypeDescription
idStringEvent Flow identifier, which must be unique within the page
triggerFunctionTriggers 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

  1. 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.
  2. 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

NameTypeDescription
idstringApplication id
labelstringApplication name
versionstringApplication version
mpAppIdstringMini Program appid
mpAppNamestringMini Program name
datasetAppDatasetGlobal data object
commonobjectGlobal common methods
setStatefunctionSets global variables

Page Instance

The current page instance is accessed via $w.page and can be quickly referenced using $page.

$w.page

NameTypeDescription
idstringCurrent page's id
labelstringCurrent page's name
pathstringCurrent page's path
datasetPageDatasetPage data object
handlerobjectPage-defined handler method
setStatefunctionSets page variables
setParamsfunctionReplaces page parameters

Device Information

Current device information is accessed via $w.device.

$w.device

NameTypeDescription
viewportobjectViewport information
networkTypestringMobile network type

Environment Information

Current environment information is accessed via $w.env.

$w.env

NameTypeDescription
typestringEnvironment type
idstringEnvironment ID

Context Information

Current context information is accessed via $w.wedaContext.

$w.wedaContext

NameTypeDescription
isEditorModebooleanWhether in the editor area
platformsarrayApplication 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

NameDescription
$w.auth.getUserInfoGets user information
$w.auth.currentUserUser information reference
$w.auth.signOutSigns out user
$w.auth.loginScopeGets user login scope

Data Source

NameDescription
$w.cloud.callDataSourceCalls data source

AI

NameDescription
$w.ai.LLM.chatChats with large language models (LLMs), supporting both streaming and non-streaming conversations.
$w.ai.bot.sendMessageConducts streaming dialogue with Agent, returning text streams and SSE event streams.
$w.ai.bot.getRecommendQuestionsGets Agent-recommended problem suggestions, returning text streams and SSE event streams
$w.ai.bot.getGets information about a specific Agent
$w.ai.bot.listBulk gets information for multiple Agents
$w.ai.bot.getChatRecordsGets chat records
$w.ai.bot.sendFeedbackSends feedback for a specific chat record
$w.ai.bot.getFeedbackGets existing feedback information
$w.ai.bot.createConversationCreates a new conversation with an Agent
$w.ai.bot.getConversationGets the conversation list
$w.ai.bot.deleteConversationDeletes the specified conversation
$w.ai.bot.speechToTextSpeech to Text
$w.ai.bot.textToSpeechText to Speech
$w.ai.bot.getTextToSpeechResultGets the text-to-speech result

Process

NameDescription
$w.cloud.callWorkflowCalls workflow

Other Cloud Capabilities

NameDescription
$w.cloud.getTempFileURLGets the http access URL for static files via cloudid
$w.cloud.getCloudInstanceReturns 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.callFunctionCalls CloudBase cloud functions, with an effect largely consistent with the $w.cloud.getCloudInstance example
$w.cloud.getUrlWithOpenidTokenIn 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

NameDescription
$w.utils.showToastDisplay a toast
$w.utils.showLoadingDisplays a global loading indicator
$w.utils.hideLoadingHides the global loading indicator
$w.utils.showModalDisplay a modal dialog
$w.utils.callPhoneMakes a phone call
$w.utils.scanCodeScan a QR code
$w.utils.setClipboardDataCopy to clipboard
$w.utils.navigateToNavigate to a specific page in the app
$w.utils.redirectToClose the current page and navigate to a page within the app
$w.utils.reLaunchClose all pages and open a specific page within the app
$w.utils.relaunchHomeReturn to the home page
$w.utils.navigateBackClose the current page and go back to the previous page or multiple pages
$w.utils.getEnumValueGets the enumeration value
$w.utils.getStorageGets cached data
$w.utils.setStorageStores data in the local cache under the specified key
$w.utils.removeStorageRemoves the specified key from the local cache
$w.utils.exportData WEBExport data to a file
$w.utils.requestSubscribeMessage Mini ProgramInvokes the client-side mini program's subscription message interface and returns the user's subscription operation result
$w.utils.openLocation Mini ProgramView a location using the WeChat built-in map
$w.utils.reserveChannelsLive Mini ProgramReserves Channels live
$w.utils.openchannelsUserProfile Mini ProgramOpen Channels Profile
$w.utils.openChannelsLive Mini ProgramOpens Channels live
$w.utils.openChannelsEvent Mini ProgramOpens Channels event page
$w.utils.openChannelsActivity Mini ProgramOpens Channels video
$w.utils.getChannelsLiveNoticeInfo Mini ProgramGets Channels live notice information
$w.utils.getChannelsLiveInfo Mini ProgramGets 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.

NameDescription
$w.ABSCalculates the absolute value of the input number.
$w.MinReturns the minimum value in a set of numbers.
$w.MaxReturns the maximum value in a set of numbers.
$w.AverageReturns the average value in a set of numbers.
$w.SumCalculates the sum of a set of numbers.
$w.FloorReturns the floor of the input number.
$w.CeilingReturns the ceiling of the input number.
$w.RoundReturns the input number rounded to the nearest integer.
$w.RandReturns a pseudo-random integer within a specified range.
$w.IfPerforms a logical comparison based on specified conditions, returning one value when conditions are met and another when they are not.
$w.IsEmptyDetermines 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.AndUsed to determine whether all conditions are true.
$w.OrReturns true if any condition is true; returns false only when all conditions are false.
$w.DateTextFormats a date and time into text of a specified format.
$w.DateTimeValueConverts date-time text to a datetime according to the specified format.
$w.NowReturns the current system time, typically used in combination with other date-time functions.
$w.GetDateReturns a date value based on the input year, month, and day values.
$w.TimestampReturns a timestamp based on the input date and time.
$w.SecondReturns the seconds based on the input date and time.
$w.MinuteReturns the minutes based on the input date and time.
$w.HourReturns the hour (in 24-hour format) from the input date and time.
$w.DayReturns the day (1-31) from the input date and time.
$w.DayOfWeekReturns the day of the week based on the input date and time.
$w.MonthReturns the month from the input date and time.
$w.YearReturns the year from the input date and time.
$w.AgeCalculates the age based on two input date and time values.
$w.AgeOfNowCalculates the current age.
$w.DateAddAdds X days to the input date and time (supports negative values).
$w.MonthAddAdds X months to the input date and time (supports negative values).
$w.YearAddAdds X years to the input date and time (supports negative values).
$w.YearDiffReturns the difference in years between two date-time fields (zero if in the same year).
$w.MonthDiffReturns the difference in months between two date-time fields (zero if in the same month).
$w.DateDiffReturns the difference in days between two date-time fields (zero if on the same day).
$w.HourDiffReturns the difference in hours between two date-time fields (zero if in the same hour).
$w.MinuteDiffReturns the difference in minutes between two date-time fields (zero if in the same minute).
$w.SecondDiffReturns the difference in seconds between two date-time fields (zero if in the same second).
$w.IsTodayDetermines whether the passed date and time is today.
$w.TimeTextFormats time into text of a specified format.
$w.LenGets the character count of the input text.
$w.ContainsDetermines whether text 1 contains text 2.
$w.SplitSplits text 1 into a text array based on the input text 2
$w.TrimRemoves all spaces and tabs at the beginning and end of the text, while preserving those in the middle.
$w.UpperConverts the input text to uppercase.
$w.LowerConverts the input text to lowercase.
$w.ConcatReturns a new text string by concatenating multiple input texts.