# JavaScript You can use a **.js** file to define the service logic of an HML page. The JS UI framework supports the JavaScript language that conforms to the ECMAScript specification. With dynamic typing, JavaScript can make your application more expressive with a flexible design. The following describes the JavaScript compilation and running. ## Syntax The ES6 syntax is supported. - **Module declaration** Import functionality modules. ``` import router from '@system.router'; ``` - **Code reference** Import JavaScript code. ``` import utils from '../../common/utils.js'; ``` ## Objects - **Application Object**
Object that is exposed in the app.js file and obtained by this.$app.$def. |
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). Do not use this attribute and private or public at the same time. |
||
DOM elements or child component instances that have registered the ref attribute. For example code, see Obtaining a DOM element. |
||
Data model of the page. Private data attribute can be modified only on the current page. |
||
Data model of the page. Behaviors of public data attributes are the same as those of the data attribute. |
||
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 Components. |
||
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 Components. |
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. |
||
|
Usage: this.$rootElement().scrollTo({ duration: 500, position: 300 }), which scrolls the page by 300 px within 500 ms. |
||
Obtains the root ViewModel instance. For example code, see Obtaining the ViewModel. |
||
Obtains the parent ViewModel instance. For example code, see Obtaining the ViewModel. |
||
Obtains the ViewModel instance of a custom child component with a specified ID. For example code, see Obtaining the ViewModel. this.$child('xxx'): Obtain the ViewModel instance of a custom child component whose ID is xxx. |
Listens for attribute changes. If the value of the data attribute changes, the bound event is triggered. For details, see Custom Components. |
scrollPageParam: ScrollPageParam |
Scrolls the page to the target position. You can specify the position using the ID selector or scrolling distance. |