官方文檔:創建自定義組件
目錄標題
- 自定義組件的基本結構
- 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 {
}