官方文档:创建自定义组件
目录标题
- 自定义组件的基本结构
- 1・struct + 自定义组件名 + {...}
- @Component
- @Entry
 
1・
2・
3・
4・
5・
6・
7・
8・
9・
10・
自定义组件的基本结构
1・struct + 自定义组件名 + {…}
struct MyComponent {build() {}
}
@Component
@Component装饰器仅能装饰struct关键字声明的数据结构。struct被@Component装饰后具备组件化的能力。
@Component
struct MyComponent {
}
@Entry
@Entry装饰的自定义组件将作为UI页面的入口。
@Entry
@Component
struct MyComponent {
}