harmony 鸿蒙Reuse Options
Reuse Options
The reuse attribute is used to specify reuse options for custom components decorated with @ReusableV2.
This document is solely for API reference. For details about the usage guidelines and constraints, see @ReusableV2 Decorator: Reusing Components.
NOTE
This feature is supported since API version 18. Updates will be marked with a superscript to indicate their earliest API version.
reuse
reuse(options: ReuseOptions)
Sets the reuse options for custom components decorated with @ReusableV2.
Atomic service API: This API can be used in atomic services since API version 18.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
options | ReuseOptions | Yes | Custom reuse configuration. |
ReuseOptions
Defines the reuse options.
Atomic service API: This API can be used in atomic services since API version 18.
System capability: SystemCapability.ArkUI.ArkUI.Full
Properties
Name | Type | Mandatory | Description |
---|---|---|---|
reuseId | ReuseIdCallback | No | Reuse ID. Components with same reuseId will be mutually reused. The default reuse ID is the component name. |
ReuseIdCallback
type ReuseIdCallback = () => string
Defines the callback used to obtain the reuse ID.
Atomic service API: This API can be used in atomic services since API version 18.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
Type | Description |
---|---|
string | Developer-specified reuse ID. It uses the component name if unspecified or if an empty string “ is provided. |
Example
@Entry
@ComponentV2
struct Index {
build() {
Column() {
ReusableV2Component()
.reuse({reuseId: () => 'reuseComponent'}) // Use 'reuseComponent' as reuseId.
ReusableV2Component()
.reuse({reuseId: () => ''}) // If an empty string is used, the component name 'ReusableV2Component' is used as reuseId.
ReusableV2Component() // If reuseId is not specified, the component name 'ReusableV2Component' is used as reuseId.
}
}
}
@ReusableV2
@ComponentV2
struct ReusableV2Component {
build() {
}
}
你可能感兴趣的鸿蒙文章
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦