目录

Declarative UI Description

ArkTS describes an application's UI by combining and extending components in a declarative manner. It also provides basic methods for configuring attributes, events, and child components to help you implement application interaction logic.

Creating a Component

You can create a component with or without parameters, depending on the component's constructor.

The new keyword is not required for component instantiation.

[h2]Without Parameters

If a component's API definition does not include mandatory constructor parameters, leave the parentheses empty. For example, the Divider component requires no parameters.

Column() {
  // ...
  Divider()
  // ...
}

[h2]With Parameters

If a component's API definition includes constructor parameters, configure the required parameters in the parentheses.

Configuring Attributes

Configure styles and other attributes using chained method calls, one per line recommended.

Configuring Events

Configure built-in component events using chained method calls, one per line recommended.

In arrow functions, this inherits its value from the surrounding (lexical) scope in which they are defined. This means that, in anonymous functions, this may present an unclear reference and is therefore not allowed in ArkTS.

Configuring Child Components

For a component with child components, for example, a container component, add the UI descriptions of the child components within trailing closures {...}. The Column, Row, Stack, Grid, and List components are all container components.