提交 eddd055a 编写于 作者: E ester.zhou

update docs

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 ccd2f913
......@@ -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. |
**Table 1** transform
| Name | Type | Description |
| ------------- | -------------------------------------- | ------------------------------------------------------------ |
| 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.
>
> ![img](figures/en-us_image_0000001127125220.png)
\ No newline at end of file
> The following figure shows the meanings of **end** and **start** in the **steps** function.
>
> ![en-us_image_0000001127125220](figures/en-us_image_0000001127125220.png)
\ No newline at end of file
......@@ -6,8 +6,7 @@ The OpenHarmony Markup Language (HML) is an HTML-like language that allows you t
## HML Page Structure
```
```html
<!-- xxx.hml -->
<div class="item-container">
<text class="item-title">Image Show</text>
......@@ -20,16 +19,19 @@ The OpenHarmony Markup Language (HML) is an HTML-like language that allows you t
## Data Binding
```
```html
<!-- xxx.hml -->
<div onclick="changeText">
<text> {{content[1]}} </text>
</div>
```
```css
/*xxx.css*/
.container{
margin: 200px;
}
```
```js
// xxx.js
export default {
data: {
......@@ -41,11 +43,13 @@ export default {
}
```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> **NOTE**
>
> - To make the array data modification take effect, use the splice method to change array items.
>
> - ECMAScript 6 (ES6) syntax is not supported in HML.
![en-us_image_0000001118642003](figures/en-us_image_0000001118642003.png)
## Common Event Binding
......@@ -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 -->
<div class="container">
<text class="title">{{count}}</text>
......@@ -74,8 +78,7 @@ Events can be written in the following formats:
</div>
```
```
```js
// xxx.js
export default {
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:
}
```
![en-us_image_0000001118642002](figures/en-us_image_0000001118642002.gif)
## Bubbling Event Binding<sup>5+</sup>
Bubbling event binding covers the following:
- 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.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> 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+ -->
<div on:touchstart.bubble="touchstartfunc"></div>
<div on: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+ -->
<div grab:touchstart.bubble="touchstartfunc"></div>
<div grab:touchstart="touchstartfunc"></div>
<!-- Bind an event callback for event bubbling.6+ -->
......@@ -159,7 +163,7 @@ Bubbling event binding covers the following:
```
```
```js
// xxx.js
export default {
clickfunc: function(e) {
......@@ -171,7 +175,8 @@ Bubbling event binding covers the following:
}
```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> **NOTE**
>
> Events bound using a traditional statement (such as onclick) will bubble only when the API version in use is 6 or later.
## Capturing Event Binding<sup>5+</sup>
......@@ -180,23 +185,23 @@ Touch events can be captured. In the capture phase, which precedes the bubbling
Event capturing binding includes:
- Bind an event callback for event capturing: on:{event}.capture.
- Bind an event callback for event capturing: **on:{event}.capture**.
- Bind an event callback, but stop the event from being captured during downward transfer: grab:{event}.capture.
- Bind an event callback, but stop the event from being captured during downward transfer: **grab:{event}.capture**.
- Example
```
```html
<!-- xxx.hml -->
<div>
<!-- Bind an event callback for event capturing.5+ --> <div on:touchstart.capture="touchstartfunc"></div>
<!-- Bind an event callback for event capturing.5+ -->
<div on:touchstart.capture="touchstartfunc"></div>
<!-- Bind an event callback, but stop the event from being captured during downward transfer.5+ -->
<div grab:touchstart.capture="touchstartfunc"></div>
</div>
```
```
```js
// xxx.js
export default {
touchstartfuc: function(e) {
......@@ -208,10 +213,9 @@ Event capturing binding includes:
## Loop Rendering
```
```html
<!-- xxx.hml -->
<div class="array-container">
<div class="array-container" style="flex-direction: column;margin: 200px;">
<!-- div loop rendering -->
<!-- By default, $item indicates the element in the array, and $idx indicates the index of the element in the array. -->
<div for="{{array}}" tid="id" onclick="changeText">
......@@ -228,8 +232,7 @@ Event capturing binding includes:
</div>
```
```
```js
// xxx.js
export default {
data: {
......@@ -248,9 +251,9 @@ export default {
}
```
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.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> **NOTE**
>
> - 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.
![en-us_image_0000001118642001](figures/en-us_image_0000001118642001.gif)
## 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:
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:
```
```html
<!-- xxx.hml -->
<div class="container">
<button class="btn" type="capsule" value="toggleShow" onclick="toggleShow"></button>
<button class="btn" type="capsule" value="toggleDisplay" onclick="toggleDisplay"></button>
<text if="{{visible}}"> Hello-World1 </text>
<text elif="{{display}}"> Hello-World2 </text>
<text if="{{visible}}"> Hello-world1 </text>
<text elif="{{display}}"> Hello-world2 </text>
<text else> Hello-World </text>
</div>
```
```
```css
/* xxx.css */
.container{
flex-direction: column;
......@@ -298,8 +301,7 @@ There are two ways to implement conditional rendering: if-elif-else or show. In
}
```
```
```js
// xxx.js
export default {
data: {
......@@ -315,10 +317,11 @@ export default {
}
```
In the optimized rendering (show), if show is true, the node is rendered properly; if it is false, the display style will be none.
![en-us_image_0000001118642004](figures/en-us_image_0000001118642004.gif)
In the optimized rendering (**show**), if **show** is **true**, the node is rendered properly; if it is false, the display style will be none.
```
```html
<!-- xxx.hml -->
<div class="container">
<button class="btn" type="capsule" value="toggle" onclick="toggle"></button>
......@@ -326,8 +329,7 @@ In the optimized rendering (show), if show is true, the node is rendered properl
</div>
```
```
```css
/* xxx.css */
.container{
flex-direction: column;
......@@ -340,8 +342,7 @@ In the optimized rendering (show), if show is true, the node is rendered properl
}
```
```
```js
// xxx.js
export default {
data: {
......@@ -353,15 +354,17 @@ export default {
}
```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> Do not use for and if attributes at the same time in an element.
> **NOTE**
>
> Do not use **for** and **if** attributes at the same time in an element.
## Logic Control Block
![en-us_image_0000001118642005](figures/en-us_image_0000001118642005.gif)
<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.
```
```html
<!-- xxx.hml -->
<list>
<block for="glasses">
......@@ -377,8 +380,7 @@ export default {
</list>
```
```
```js
// xxx.js
export default {
data: {
......@@ -390,12 +392,13 @@ export default {
}
```
## Template Reference
![en-us_image_0000001118642006](figures/en-us_image_0000001118642006.png)
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 -->
<div class="item">
<text>Name: {{name}}</text>
......@@ -403,8 +406,7 @@ HML supports using elements to reference template files. For details, see Custom
</div>
```
```
```html
<!-- index.hml -->
<element name='comp' src='../../common/template.hml'></element>
<div>
......
......@@ -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
import router from '@system.router';
```
- Code reference
Import JavaScript code.
```
```js
import utils from '../../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
export default {
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
export default {
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 &lt;tag xxxx='value'&gt;. 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 &lt;tag xxxx='value'&gt;. 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
export default {
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. |
Example:
Example
```
this.$rootElement.scrollTo({position: 0})
this.$rootElement.scrollTo({id: 'id', duration: 200, timingFunction: 'ease-in', complete: ()=>void})
```js
this.$rootElement().scrollTo({position: 0})
this.$rootElement().scrollTo({id: 'id', duration: 200, timingFunction: 'ease-in', complete: ()=>void})
```
## Obtaining a DOM Element
1. Use $refs to obtain a DOM element.
1. Use `$refs` to obtain a DOM element.
```
```html
<!-- index.hml -->
<div class="container">
<image-animator class="image-player" ref="animator" images="{{images}}" duration="1s" onclick="handleClick"></image-animator>
</div>
```
```
```js
// index.js
export default {
data: {
......@@ -190,17 +188,16 @@ The ES6 syntax is supported.
};
```
2. Call $element to obtain a DOM element.
2. Call `$element` to obtain a DOM element.
```
```html
<!-- index.hml -->
<div class="container">
<div class="container" style="width:500px;height: 700px; margin: 100px;">
<image-animator class="image-player" id="animator" images="{{images}}" duration="1s" onclick="handleClick"></image-animator>
</div>
```
```
```js
// index.js
export default {
data: {
......@@ -224,12 +221,13 @@ The ES6 syntax is supported.
};
```
![en-us_image_0000001118642007](figures/en-us_image_0000001118642007.gif)
## Obtaining the ViewModel
The following shows files of the root page:
```
```html
<!-- root.hml -->
<element name='parentComp' src='../../common/component/parent/parent.hml'></element>
<div class="container">
......@@ -240,8 +238,7 @@ The following shows files of the root page:
</div>
```
```
```js
// root.js
export default {
data: {
......@@ -250,10 +247,11 @@ export default {
}
```
Customize the parent component.
![en-us_image_0000001118642008](figures/en-us_image_0000001118642008.png)
Customize the parent component.
```
```html
<!-- parent.hml -->
<element name='childComp' src='../child/child.hml'></element>
<div class="item" onclick="textClicked">
......@@ -263,8 +261,7 @@ Customize the parent component.
</div>
```
```
```js
// parent.js
export default {
data: {
......@@ -283,25 +280,23 @@ export default {
Customize the child component.
```
```html
<!-- child.hml -->
<div class="item" onclick="textClicked">
<text class="text-style" onclick="childClicked">Child component clicked</text>
<text class="text-style" if="{{show}}">Hello child component</text>
<text class="text-style" if="{{isShow}}">Hello child component</text>
</div>
```
```
```js
// child.js
export default {
data: {
show: false,
isShow: false,
text: 'I am the child component!',
},
childClicked () {
this.show = !this.show;
this.isShow = !this.isShow;
console.info('child component get parent text');
console.info('${this.$parent().text}');
console.info('child component get root text');
......@@ -309,3 +304,5 @@ export default {
},
}
```
![en-us_image_0000001118642009](figures/en-us_image_0000001118642009.gif)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册