@Extend 装饰器:定义扩展组件样式
注意
@Extend 仅支持在全局定义,不支持在组件内部定义。
@Extend 可以传递参数
@Extend 是针对某一个特定的组件,不能 import,只能当前文件
装饰器使用说明
语法
bash
@Extend(UIComponentName) function functionName { ... }
使用规则
ts
// Text 组件
@Extend(Text)
function customStyle(size: number, cb: () => void) {
.fontSize(size)
.textAlign(TextAlign.Center)
.width(200)
.height(200)
.backgroundColor(Color.Black)
.fontColor(Color.Yellow)
.onClick(() => {
cb()
})
}
@Entry
@Component
struct Index2 {
handleClick() {
console.log("哈哈哈哈")
}
build() {
Text("测试结果").customStyle(26, this.handleClick)
}
}