1 # 复用标识
2 
3 reuseId用于标记自定义组件复用组,当组件回收复用时,复用框架将根据组件的reuseId来划分组件的复用组。
4 
5 >  **说明:**
6 >
7 > 从API Version 10开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
8 
9 
10 ## reuseId
11 
12 reuseId(id: string)
13 
14 复用标识,用于划分自定义组件的复用组。
15 
16 **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
17 
18 **系统能力:** SystemCapability.ArkUI.ArkUI.Full
19 
20 **参数:**
21 
22 | 参数名 | 类型   | 必填 | 说明                                   |
23 | ------ | ------ | ---- | -------------------------------------- |
24 | id     | string | 是   | 复用标识,用于划分自定义组件的复用组。 |
25 
26 ## 示例
27 
28 该示例通过reused标识自定义组件的复用组。
29 
30 ```ts
31 // xxx.ets
32 @Entry
33 @Component
34 struct MyComponent {
35   @State switch: boolean = true;
36   private type: string = "type1";
37 
38   build() {
39     Column() {
40       Button("ChangeType")
41         .onClick(() => {
42           this.type = "type2"
43         })
44       Button("Switch")
45         .onClick(() => {
46           this.switch = !this.switch
47         })
48       if (this.switch) {
49         ReusableChildComponent({ type: this.type })
50           .reuseId(this.type)
51       }
52     }
53     .width('100%')
54     .height('100%')
55   }
56 }
57 
58 @Reusable
59 @Component
60 struct ReusableChildComponent {
61   @State type: string = ''
62 
63   aboutToAppear() {
64     console.log(`ReusableChildComponent Appear ${this.type}`)
65   }
66 
67   aboutToReuse(params: ESObject) {
68     console.log(`ReusableChildComponent Reuse ${this.type}`)
69     this.type = params.type;
70   }
71 
72   build() {
73     Row() {
74       Text(this.type)
75         .fontSize(20)
76         .margin({ left: 10 })
77     }.margin({ left: 10, right: 10 })
78   }
79 }
80 ```
81