How to Use Local Variables for Page-to-Page Data Transfer in Frontend Apps
This guide explains the purpose and naming rules of local variables, walks through creating a calculator page with named inputs and button click events, shows how to combine logical conditions using && and ||, and contrasts local variables with global variables for cross‑page data sharing.
Local Variables Overview
Local variables are scoped to a single event or action on a page. They exist only while the event is executing and are automatically cleared when the event finishes. Variable identifiers may contain only English letters (A‑Z, a‑z) and digits (0‑9); Chinese characters or other symbols are not permitted.
Example: Building a Simple Calculator
Create the page and name input controls . Each input field (e.g., num1, num2, operator) receives a unique identifier that will be used as the local variable name.
Attach a mouse‑click event to the “Calculate” button . In the event handler you can read the input values, perform the arithmetic, and store the result in a local variable such as result. The following screenshots show the configuration steps in the visual editor.
Logical Expressions in Variable Assignments
When a condition requires multiple criteria, the platform follows standard programming syntax:
Logical AND: && Logical OR: || Example: to select female users aged 18 or older, use the expression
[[ age >= 18 && gender == "female" ]]Scope Comparison
Local variables are valid only within the action that defines them; after the action completes they are discarded. In contrast, global variables persist across pages and actions, allowing values to be shared for cross‑page data transmission.
AI Software Product Manager
Daily updates of Xiaomi's latest AI internal materials
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
