@@ -19,34 +19,34 @@ Components support dynamic rotation, translation, and scaling effects. These eff
| animation-direction<sup>6+</sup> | string | normal | Mode of playing the animation. <br>- **normal**: Plays the animation in forward loop mode. <br>- **reverse**: Plays the animation in reverse loop mode. <br>- **alternate**: Plays the animation in alternating loop mode. When the animation is played for an odd number of times, the playback is in forward direction. When the animation is played for an even number of times, the playback is in backward direction. <br>- **alternate-reverse**: Plays the animation in reverse-alternating loop mode. When the animation is played for an odd number of times, the playback is in backward direction. When the animation is played for an even number of times, the playback is in forward direction. |
| animation-fill-mode | string | none | Start and end styles of the animation <br>- **none**: No style is applied to the target before or after the animation is executed. <br>- **forwards**: The target keeps the state at the end of the animation (defined in the last key frame) after the animation is executed. <br>- **backwards**<sup>6+</sup>: The animation uses the value defined in the first key frame during the **animation-delay**. When **animation-direction** is set to **normal** or **alternate**, the value in the **from** key frame is used. When **animation-direction** is set to **reverse** or **alternate-reverse**, the value in the **to** key frame is used.. <br>- **both**<sup>6+</sup>: The animation follows the **forwards** and **backwards** rules. |
| animation-play-state<sup>6+</sup> | string | running | Current state of the animation. <br>- **paused**: paused <br>- **running**: playing |
| transition<sup>6+</sup> | string | all 0 ease 0 | Transition effect when the component status is switched. The following four attributes can be set through the <br>- **transition** attribute:**transition-property**: name of the CSS property for setting the transition effect. Currently, the width, height, and background color are supported. <br>- **transition-duration**: duration required for completing the transition effect, in seconds. <br>- **transition-timing-function**: time curve of the transition effect. The curve provided by the style animation is supported. <br>- **transition-delay**: delay for starting the transition effect, in seconds. |
| transition<sup>6+</sup> | string | all 0 ease 0 | Transition effect when the component status is switched. The following four attributes can be set through the **transition** attribute.<br>-**transition-property**: name of the CSS property for setting the transition effect. Currently, the width, height, and background color are supported. <br>- **transition-duration**: duration required for completing the transition effect, in seconds. <br>- **transition-timing-function**: time curve of the transition effect. The curve provided by the style animation is supported. <br>- **transition-delay**: delay for starting the transition effect, in seconds. |
| none<sup>6+</sup> | - | No conversion is performed. |
| matrix<sup>6+</sup> | \<number> | A matrix of six values, which represent scaleX, skewY, skewX, scaleY, translateX, translateY. |
| matrix3d<sup>6+</sup> | \<number> | A 4x4 matrix of 16 values. |
| translate | \<length> \|\<percent> | Moves an element along the x-axis and y-axis. |
| translate3d<sup>6+</sup> | \<length> \|\<percent> | Three input parameters, indicating the translation distance of the x-axis, y-axis, and z-axis, respectively. |
| none<sup>6+</sup> | - | Does not perform any transformation. |
| matrix<sup>6+</sup> | \<number> | Defines a matrix of six values, which represent scaleX, skewY, skewX, scaleY, translateX, translateY. |
| matrix3d<sup>6+</sup> | \<number> | Defines a 4x4 matrix of 16 values. |
| translate | \<length> \|\<percent> | Moves an element in 2D space. |
| translate3d<sup>6+</sup> | \<length> \|\<percent> | Moves an element in 3D space. There are three input parameters, indicating the translation distance of the x-axis, y-axis, and z-axis, respectively. |
| translateX | \<length> \|\<percent> | Moves an element along the x-axis. |
| translateY | \<length> \|\<percent> | Moves an element along the y-axis. |
| translateZ<sup>6+</sup> | \<length> \|\<percent> | Translation distance of the z-axis |
| scale | \<number> | Changes the size of an element. You need to set the target width and height on the x-axis and y-axis. |
| scale3d<sup>6+</sup> | \<number> | Three input parameters, indicating the scale ratio of the x-axis, y-axis, and z-axis, respectively. |
| scaleX | \<number> | Changes the element width. |
| scaleY | \<number> | Changes the element height. |
| scaleZ<sup>6+</sup> | \<number> | Scale ratio of the z-axis. |
| rotate | \<deg> \|\<rad> \|\<grad><sup>6+</sup>\|\<turn><sup>6+</sup> | Rotates an element. You can set the element to rotate around its x-axis or y-axis. |
| rotate3d<sup>6+</sup> | \<deg> \|\<rad> \|\<grad> \|\<turn> | Four input parameters: The first three parameters are the rotation vectors of the x-axis, y-axis, and z-axis, and the fourth parameter is the rotation angle. |
| translateZ<sup>6+</sup> | \<length> \|\<percent> | Moves an element along the z-axis. |
| scale | \<number> | Resizes an element in 2D space. You need to set the target width and height on the x-axis and y-axis. |
| scale3d<sup>6+</sup> | \<number> | Resizes an element in 3D space. There are three input parameters, indicating the scale ratio of the x-axis, y-axis, and z-axis, respectively. |
| scaleX | \<number> | Resizes an element along the x-axis. |
| scaleY | \<number> | Resizes an element along the y-axis. |
| scaleZ<sup>6+</sup> | \<number> | Resizes an element along the z-axis. |
| rotate | \<deg> \|\<rad> \|\<grad><sup>6+</sup>\|\<turn><sup>6+</sup> | Rotates an element in 2D space. You can set the element to rotate around its x-axis or y-axis. |
| rotate3d<sup>6+</sup> | \<deg> \|\<rad> \|\<grad> \|\<turn> | Rotates an element in 3D space. There are four input parameters: The first three parameters are the rotation vectors of the x-axis, y-axis, and z-axis, and the fourth parameter is the rotation angle. |
| rotateX | \<deg> \|\<rad> \|\<grad><sup>6+</sup>\|\<turn><sup>6+</sup> | Rotates an element around the x-axis. |
| rotateY | \<deg> \|\<rad> \|\<grad><sup>6+</sup>\|\<turn><sup>6+</sup> | Rotates an element around the y-axis. |
| rotateZ<sup>6+</sup> | \<deg> \|\<rad> \|\<grad> \|\<turn> | Rotation angle in the z-axis direction. |
| skew<sup>6+</sup> | \<deg> \|\<rad> \|\<grad> \|\<turn> | Two input parameters, indicating the 2D skew angle of the x-axis and y-axis, respectively. |
| skewX<sup>6+</sup> | \<deg> \|\<rad> \|\<grad> \|\<turn> | 2D skew angle of the x-axis. |
| skewY<sup>6+</sup> | \<deg> \|\<rad> \|\<grad> \|\<turn> | 2D skew angle of the y-axis. |
| perspective<sup>6+</sup> | \<number> | Distance from the lens to the element's surface in the 3D perspective scenario. |
| rotateZ<sup>6+</sup> | \<deg> \|\<rad> \|\<grad> \|\<turn> | Rotates an element around the z-axis. |
| skew<sup>6+</sup> | \<deg> \|\<rad> \|\<grad> \|\<turn> | Skews an element in 2D space. There are two input parameters, indicating the 2D skew angle of the x-axis and y-axis, respectively. |
| skewX<sup>6+</sup> | \<deg> \|\<rad> \|\<grad> \|\<turn> | Skews an element along the x-axis in 2D space. |
| skewY<sup>6+</sup> | \<deg> \|\<rad> \|\<grad> \|\<turn> | Skews an element along the y-axis in 2D space. |
| perspective<sup>6+</sup> | \<number> | Sets the distance from the lens to the element's surface in the 3D perspective scenario. |
**Table 2** @keyframes
...
...
@@ -56,8 +56,8 @@ Components support dynamic rotation, translation, and scaling effects. These eff
| opacity | number | 1 | Opacity value applied to the component after the animation is played. The value ranges from **0** to **1**. The default value is **1**. |
| width | \<length> | - | Width value applied to the component after the animation is played. |
| height | \<length> | - | Height value applied to the component after the animation is played. |
| transform | string | - | Transformation type applied to a component. For details, see **transform**. |
| background-position<sup>6+</sup> | string \|\<percentage> \|\<length> string \|\<percentage> \|\<length> | 50% 50% | Set the background image for a window. The unit can be percentage or px. The first value indicates the horizontal position, and the second value indicates the vertical position. If only one value is specified, the other one is **50%**. The available values for the first string are **left**, **center**, and **right**. The available values for the second string are **top**, **center**, and **bottom**.<br>Example:<br>- background-position: 200px 30%<br>- background-position: 100px top<br>- background-position: center center |
| transform | string | - | Transformation type applied to the component. For details, see **transform**. |
| background-position<sup>6+</sup> | string \|\<percentage> \|\<length> string \|\<percentage> \|\<length> | 50% 50% | Position of the background image. The unit can be percentage or px. The first value indicates the horizontal position, and the second value indicates the vertical position. If only one value is specified, the other one is **50%**. The available values for the first string are **left**, **center**, and **right**. The available values for the second string are **top**, **center**, and **bottom**.<br>Example:<br>- background-position: 200px 30%<br>- background-position: 100px top<br>- background-position: center center |
If there is no default value for when an animation will start or end, use **from** and **to** to specify the start and end of the display. You can use a percentage value to specify an intermediate state of the animation.<sup>6+</sup> The following is an example:
...
...
@@ -211,7 +211,8 @@ export default {
> **NOTE**
>
> The @keyframes rule with **from** and **to** defined cannot be dynamically bound to an element.
> The following figure shows the meanings of end and start in the steps function.
> The @keyframes rule with **from** and **to** defined cannot be dynamically bound to an element.
@@ -53,13 +57,13 @@ Events are bound to components through 'on' or '@'. When a component triggers an
Events can be written in the following formats:
-funcName: name of the event callback, which is implemented by defining the corresponding function in the .js file.
-"funcName": name of the event callback, which is implemented by defining the corresponding function in the .js file.
-funcName(a,b): function parameters, such as a and b, which can be constants, or variables defined in data in the .js file. Do not add the prefix this. to variables.
-"funcName(a,b)": function parameters, such as a and b, which can be constants, or variables defined in data in the .js file. Do not add the prefix this. to variables.
- Example
```
```html
<!-- xxx.hml -->
<divclass="container">
<textclass="title">{{count}}</text>
...
...
@@ -74,8 +78,7 @@ Events can be written in the following formats:
</div>
```
```
```js
// xxx.js
exportdefault{
data:{
...
...
@@ -93,8 +96,7 @@ Events can be written in the following formats:
};
```
```
```css
/* xxx.css */
.container{
display:flex;
...
...
@@ -127,26 +129,28 @@ Events can be written in the following formats:
> For details about bubbling events, see [Universal Events](../reference/arkui-js/js-components-common-events.md)
- Bind an event callback for event bubbling: **on:{event}.bubble**. **on:{event}** is equivalent to **on:{event}.bubble**.
- Bind an event callback, but stop the event from bubbling upwards: **grab:{event}.bubble**. **grab:{event}** is equivalent to **grab:{event}.bubble**.
> **NOTE**
>
> For details about bubbling events, see [Universal Events](../reference/arkui-js/js-components-common-events.md).
- Example
```
```html
<!-- xxx.hml -->
<div>
<!-- Bind an event callback for event bubbling.5+ -->
<divon:touchstart.bubble="touchstartfunc"></div>
<divon:touchstart="touchstartfunc"></div>
<!-- Bind an event callback, but stop the event from bubbling upwards.5+ -->
<!-- Bind an event callback, but stop the event from bubbling upwards.5+ -->
The tid attribute accelerates the for loop and improves the re-rendering efficiency when data in a loop changes.
The **tid** attribute accelerates the for loop and improves the re-rendering efficiency when data in a loop changes.
The tid attribute specifies the unique ID of each element in the array. If it is not specified, the index of each element in the array is used as the ID. For example, tid="id" indicates that the id attribute of each element is its unique ID.
The **tid** attribute specifies the unique ID of each element in the array. If it is not specified, the index of each element in the array is used as the ID. For example, **tid="id"** indicates that the **id** attribute of each element is its unique ID.
The for loop supports the following statements:
...
...
@@ -260,32 +263,32 @@ The for loop supports the following statements:
- for="(i, v) in array": i indicates the element index, and v indicates the element variable. All elements of the array object will be looped through.
> - Each element in the array must have the data attribute specified by tid. Otherwise, an exception may occur.
>
> - The attribute specified by tid in the array must be unique. Otherwise, performance loss occurs. In the above example, only id and name can be used as tid because they are unique fields.
> - The attribute specified by **tid** in the array must be unique. Otherwise, performance loss occurs. In the above example, only **id** and **name** can be used as **tid** because they are unique fields.
>
> - The tid field does not support expressions.
> - The **tid** field does not support expressions.
There are two ways to implement conditional rendering: if-elif-else or show. In if-elif-else, when the if statement evaluates to false, the component is not built in the VDOM and is not rendered. For show, when show is false, the component is not rendered but is built in the VDOM. In addition, the if-elif-else statements must be used in sibling nodes. Otherwise, the compilation fails. The following example uses both ways to implement conditional rendering:
There are two ways to implement conditional rendering: **if-elif-else** or **show**. In **if-elif-else**, when the if statement evaluates to **false**, the component is not built in the VDOM and is not rendered. For show, when **show** is **false**, the component is not rendered but is built in the VDOM. In addition, the **if-elif-else** statements must be used in sibling nodes. Otherwise, the compilation fails. The following example uses both ways to implement conditional rendering:
<block> makes loop rendering and conditional rendering more flexible. A <block> will not be compiled as a real component. **NOTE** that the <block> tag supports only the for and if attributes.
## Logic Control Block
**\<block>** makes loop rendering and conditional rendering more flexible. A \<block> will not be compiled as a real component. Note that the **\<block>** tag supports only the for and if attributes.
HML supports using elements to reference template files. For details, see Custom Components.
## Template Reference
HML supports using `element` to reference template files. For details, see [Custom Components](../reference/arkui-js/js-components-custom-basic-usage.md).
```
```html
<!-- template.hml -->
<divclass="item">
<text>Name: {{name}}</text>
...
...
@@ -403,8 +406,7 @@ HML supports using elements to reference template files. For details, see Custom
@@ -9,40 +9,39 @@ You can use a .js file in the ECMAScript compliant JavaScript language to define
The ES6 syntax is supported.
- Module declaration
Import functionality modules.
```
```js
importrouterfrom'@system.router';
```
- Code reference
Import JavaScript code.
```
```js
importutilsfrom'../../common/utils.js';
```
## Objects
- Application Object
| Attribute | Type | Description |
- Application objects
| Name | Type | Description |
| -------- | -------- | -------- |
| $def | Object | Object that is exposed in the app.js file and obtained by this.$app.$def.<br/>> ![icon-note.gif](public_sys-resources/icon-note.gif)**NOTE**:<br/>> Application objects do not support data binding. Data update should be triggered on the UI. |
| $def | Object | Object that is exposed in the app.js file and obtained by `this.$app.$def`.<br/>> **NOTE**<br/>> Application objects do not support data binding. Data update should be triggered on the UI. |
Example Code
Example
```
```js
// app.js
exportdefault{
onCreate(){
console.info('AceApplication onCreate');
console.info('Application onCreate');
},
onDestroy(){
console.info('AceApplication onDestroy');
console.info('Application onDestroy');
},
globalData:{
appData:'appData',
...
...
@@ -56,7 +55,7 @@ The ES6 syntax is supported.
```
```
```js
// index.js
exportdefault{
data:{
...
...
@@ -77,27 +76,27 @@ The ES6 syntax is supported.
```
- Page objects
| Attribute | Type | Description |
| Attribute | Type | Description |
| -------- | -------- | -------- |
| data | Object/Function | Data model of the page. If the attribute is of the function type, the return value must be of the object type. The attribute name cannot start with a dollar sign ($) or underscore (_). Do not use reserved words (for, if, show, and tid).<br/>Do not use this attribute and private or public at the same time. |
| $refs | Object | DOM elements or child component instances that have registered the ref attribute. For example code, see [Obtaining a DOM element](#obtaining-a-dom-element). |
| private | Object | Data model of the page. Private data attribute can be modified only on the current page. |
| public | Object | Data model of the page. Behaviors of public data attributes are the same as those of the data attribute. |
| props | Array/Object | Used for communication between components. This attribute can be transferred to components via <tag xxxx='value'>. A props name must be in lowercase and cannot start with a dollar sign ($) or underscore (_). Do not use reserved words (for, if, show, and tid). Currently, props does not support functions. For details, see [Custom Component](../reference/arkui-js/js-components-custom-props.md). |
| computed | Object | Used for pre-processing an object for reading and setting. The result is cached. The name cannot start with a dollar sign ($) or underscore (_). Do not use reserved words. For details, see [Custom Component](../reference/arkui-js/js-components-custom-props.md). |
| props | Array/Object | Used for communication between components. This attribute can be transferred to components via <tag xxxx='value'>. A props name must be in lowercase and cannot start with a dollar sign ($) or underscore (_). Do not use reserved words (for, if, show, and tid). Currently, props does not support functions. For details, see [props](../reference/arkui-js/js-components-custom-props.md). |
| computed | Object | Used for pre-processing an object for reading and setting. The result is cached. The name cannot start with a dollar sign ($) or underscore (_). Do not use reserved words. For details, see [props](../reference/arkui-js/js-components-custom-props.md). |
## Functions
## Methods
- Data functions
| Function | Parameter | Description |
- Data methods
| Name | Parameter | Description |
| -------- | -------- | -------- |
| $set | key: string, value: any | Adds an attribute or modifies an existing attribute.<br/>Usage:<br/>this.$set('_key_',_value_): Add an attribute. |
| $delete | key: string | Deletes an attribute.<br/>Usage:<br/>this.$delete('_key_'): Delete an attribute. |
| $set | key: string, value: any | Adds an attribute or modifies an existing attribute.<br/>Usage:<br/>this.$set('_key_',_value_): Add an attribute. |
| $delete | key: string | Deletes an attribute.<br/>Usage:<br/>this.$delete('key'): Delete an attribute. |
Example Code
Example
```
```js
// index.js
exportdefault{
data:{
...
...
@@ -116,57 +115,56 @@ The ES6 syntax is supported.
}
```
- Public functions
| Function | Parameter | Description |
- Public methods
| Name | Parameter | Description |
| -------- | -------- | -------- |
| $element | id: string | Obtains the component with a specified ID. If no ID is specified, the root component is returned. For example code, see [Obtaining a DOM element](#obtaining-a-dom-element).<br/>Usage:<br/>```<div id='_xxx_'></div>```<br/>- this.$element('_xxx_'): Obtain the component whose ID is _xxx_.<br/>- this.$element(): Obtain the root component. |
| $rootElement | None | Obtains the root element.<br/>Usage: this.$rootElement().scrollTo({ duration: 500, position: 300 }), which scrolls the page by 300 px within 500 ms. |
| $root | N/A | Obtains the root ViewModel instance. For example code, see [Obtaining the ViewModel](#obtaining-the-viewmodel). |
| $parent | N/A | Obtains the parent ViewModel instance. For example code, see [Obtaining the ViewModel](#obtaining-the-viewmodel). |
| $child | id: string | Obtains the ViewModel instance of a custom child component with a specified ID. For example code, see [Obtaining the ViewModel](#obtaining-the-viewmodel).<br/>Usage:<br/>this.$child('_xxx_'): Obtain the ViewModel instance of a custom child component whose ID is _xxx_. |
| $child | id: string | Obtains the ViewModel instance of a custom child component with a specified ID. For example code, see [Obtaining the ViewModel](#obtaining-the-viewmodel).<br/>Usage:<br/>this.$child('xxx'): Obtain the ViewModel instance of a custom child component whose ID is _xxx_. |
- Event function
| Function | Parameter | Description |
- Event methods
| Name | Parameter | Description |
| -------- | -------- | -------- |
| $watch | data: string, callback: string \| Function | Listens for attribute changes. If the value of the data attribute changes, the bound event is triggered. For details, see [Custom Component](../reference/arkui-js/js-components-custom-props.md)<br/>Usage:<br/>this.$watch('_key_',_callback_) |
| $watch | data: string, callback: string \| Function | Listens for attribute changes. If the value of the data attribute changes, the bound event is triggered. For details, see [props](../reference/arkui-js/js-components-custom-props.md)<br/>Usage:<br/>this.$watch('key', callback) |
- Page function
| Function | Parameter | Description |
- Page methods
| Name | Parameter | Description |
| -------- | -------- | -------- |
| scrollTo<sup>6+</sup> | scrollPageParam: ScrollPageParam | Scrolls the page to the target position. You can specify the position using the ID selector or scrolling distance. |
Table1 ScrollPageParam<sup>6+</sup>
**Table 1** ScrollPageParam<sup>6+</sup>
| Name | Type | Default Value | Description |
| -------- | -------- | -------- | -------- |
| position | number | - | Position to scroll to. |
| id | string | - | ID of the element to be scrolled to. |
| duration | number | 300 | Scrolling duration, in milliseconds. |
| timingFunction | string | ease | Animation curve for scrolling. Available option:<br/>[Animation Styles](../reference/arkui-js/js-components-common-animation.md) |
| timingFunction | string | ease | Animation curve for scrolling. Available options:<br/>[Animation Styles](../reference/arkui-js/js-components-common-animation.md) |
| complete | () => void | - | Callback to be invoked when the scrolling is complete. |