鸿蒙学习笔记
第五节 @Extend的学习
为了让@Style这种方便的类型更加通用
我们加入了@Extend针对于某一个组件
例如
@Extend(Text) function sizeColor(fs:number,fc:string|Color){
.fontSize(fs)
.fontColor(fc)
}
@Extend(Text) function textStyle(fs:number,fc:string| Color){
.sizeColor(fs,fc)
.fontWeight(FontWeight.Bold)
.fontStyle(FontStyle.Italic)
}
//参数也可以直接传方法
@Extend(Button) function butAction(c:()=> void){
.fontSize(32)
.width(140)
.height(140)
.onClick(()=>{
c()
})
}
调用与@Style类似,只是可以传参数
演示传方法的代码
Button(this.num.toString()).butAction(()=>{
this.num++
})