We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

Universal Attributes

NOTE

Supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.

Common Attributes

PhonePC/2in1TabletTVWearable

Common attributes are used to set component identities and appearance.

Expand
Name Type Default Value Mandatory Description
id string - No Unique ID of the component.
style string - No Style declaration of the component.
class string - No Style class of the component, which is used to refer to a style table.
ref string - No Reference information of child elements or child components, which is registered with the parent component on $refs.
disabled boolean false No Whether the component is disabled. If it is disabled, it cannot respond to user interaction. The value true indicates the component does not respond to interaction events, and false indicates the opposite.
data string - No

Attribute set for the component to facilitate data storage and reading. In the JS file:

- Use e.target.attr.data to read data in the event callback, where e is the input parameter.

- Use $element or $refs to obtain a DOM element, which can then be accessed through attr.data.

You are advised to use data-* instead since API version 6.

data-*6+ string - No

Attribute set for the component to facilitate data storage and reading. The value is case insensitive. For example, data-A and data-a are the same by default. In the JS file:

- Use e.target.dataSet.a to read data in the event callback, where e is the input parameter.

- After a DOM element is obtained by using $element or $refs, it can be accessed through dataSet.a.

click-effect5+ string - No

Click effect complying with spring physics. Available values are as follows:

- spring-small: The component scales down to 90% of its size when it is selected. This is appropriate for small components.

- spring-medium: The component scales down to 95% of its size when it is selected. This is appropriate for medium-sized components.

- spring-large: The component scales down to 95% of its size when it is selected. This is appropriate for large components.

dir6+ string auto No

Element layout mode. Available values are as follows:

- rtl: right-to-left layout.

- ltr: left-to-right layout.

- auto: follows the system language environment.

Rendering Attributes

PhonePC/2in1TabletTVWearable

Rendering attributes are used to set whether a component is rendered.

Expand
Name Type Default Value Description
for Array - Expands the current element based on the configured data list.
if boolean - Whether the element is added or removed. The value true indicates that the element is added, and false indicates that the element is removed.
show boolean - Whether the element is displayed or hidden. The value true indicates that the element is displayed, and false indicates that the element is hidden.
NOTE

Do not set styles in attribute fields.

Example

PhonePC/2in1TabletTVWearable

Example 1

PhonePC/2in1TabletTVWearable
Collapse
Word wrap
Dark theme
Copy code
  1. <!-- xxx.hml -->
  2. <div id="container">
  3. <button class="btn" type="capsule" value="toggleDisplay" onclick="toggleDisplay"></button>
  4. <list class="list">
  5. <list-item for="{{ array }}" class="listItem">
  6. <text class="text" onclick="toggleShow" show="{{ visible }}"
  7. if="{{ display }}">{{ $item.value }}</text>
  8. </list-item>
  9. </list>
  10. </div>
Collapse
Word wrap
Dark theme
Copy code
  1. /* xxx.css */
  2. #container {
  3. flex-direction: column;
  4. width: 100%;
  5. margin-top: 10px;
  6. }
  7. .text {
  8. font-size: 50px;
  9. font-weight: 500;
  10. margin-left: 12px;
  11. }
  12. .listItem {
  13. width: 100%;
  14. height: 100px;
  15. line-height: 60px;
  16. border-bottom: 1px solid #DEDEDE;
  17. font-size: 20px;
  18. }
  19. .btn{
  20. width: 280px;
  21. font-size: 26px;
  22. margin: 10px 0;
  23. }
Collapse
Word wrap
Dark theme
Copy code
  1. // xxx.js
  2. export default {
  3. data: {
  4. visible: true,
  5. display: true,
  6. title: "",
  7. i: 4,
  8. array: [
  9. {"value": "List text 0"},
  10. {"value": "List text 1"},
  11. {"value": "List text 2"},
  12. {"value": "List text 3"},
  13. ],
  14. },
  15. toggleShow: function() {
  16. this.array.push({"value": "List text " + this.i })
  17. this.i++
  18. },
  19. toggleDisplay: function() {
  20. this.display = !this.display
  21. },
  22. }

Example 2

PhonePC/2in1TabletTVWearable
Collapse
Word wrap
Dark theme
Copy code
  1. <!-- xxx.hml -->
  2. <div class="container">
  3. <div>
  4. <text class="text1" dir='rtl' >hello world</text>
  5. </div>
  6. <div>
  7. <text class="text2" dir='ltr' >hello world</text>
  8. </div>
  9. </div>
Collapse
Word wrap
Dark theme
Copy code
  1. /* xxx.css */
  2. .container {
  3. display: flex;
  4. flex-direction: column;
  5. justify-content: center;
  6. align-items: center;
  7. width: 100%;
  8. height: 100%;
  9. }
  10. .text1{
  11. width: 90%;
  12. height: 100px;
  13. background-color: aqua;
  14. }
  15. .text2{
  16. width: 90%;
  17. height: 100px;
  18. background-color: blue;
  19. }

Search in References
Enter a keyword.