当前位置: 首页 > news >正文

比较好的网站公司汕头网站推广排名

比较好的网站公司,汕头网站推广排名,wordpress怎么添加附件,织梦系统网站打开速度慢定义扩展组件样式:Extend装饰器 在前文的示例中,可以使用Styles用于样式的重用,在Styles的基础上,我们提供了Extend,用于扩展原生组件样式。 说明 从API version 9开始,该装饰器支持在ArkTS卡片中使用。 从…

定义扩展组件样式:@Extend装饰器

在前文的示例中,可以使用@Styles用于样式的重用,在@Styles的基础上,我们提供了@Extend,用于扩展原生组件样式。

说明

从API version 9开始,该装饰器支持在ArkTS卡片中使用。

从API version 11开始,该装饰器支持在元服务中使用。

装饰器使用说明

语法

@Extend(UIComponentName) function functionName { ... }

使用规则

  • 和@Styles不同,@Extend仅支持在全局定义,不支持在组件内部定义。

说明

只能在当前文件内使用,不支持export

如果想实现export功能,推荐使用AttributeModifier

  • 和@Styles不同,@Extend支持封装指定组件的私有属性、私有事件和自身定义的全局方法。

    // @Extend(Text)可以支持Text的私有属性fontColor
    @Extend(Text) function fancy () {.fontColor(Color.Red)
    }
    // superFancyText可以调用预定义的fancy
    @Extend(Text) function superFancyText(size:number) {.fontSize(size).fancy()
    }
  • 和@Styles不同,@Extend装饰的方法支持参数,开发者可以在调用时传递参数,调用遵循TS方法传值调用。

    // xxx.ets
    @Extend(Text) function fancy (fontSize: number) {.fontColor(Color.Red).fontSize(fontSize)
    }@Entry
    @Component
    struct FancyUse {build() {Row({ space: 10 }) {Text('Fancy').fancy(16)Text('Fancy').fancy(24)}}
    }
  • @Extend装饰的方法的参数可以为function,作为Event事件的句柄。

    @Extend(Text) function makeMeClick(onClick: () => void) {.backgroundColor(Color.Blue).onClick(onClick)
    }@Entry
    @Component
    struct FancyUse {@State label: string = 'Hello World';onClickHandler() {this.label = 'Hello ArkUI';}build() {Row({ space: 10 }) {Text(`${this.label}`).makeMeClick(() => {this.onClickHandler()})}}
    }
  • @Extend的参数可以为状态变量,当状态变量改变时,UI可以正常的被刷新渲染。

    @Extend(Text) function fancy (fontSize: number) {.fontColor(Color.Red).fontSize(fontSize)
    }@Entry
    @Component
    struct FancyUse {@State fontSizeValue: number = 20build() {Row({ space: 10 }) {Text('Fancy').fancy(this.fontSizeValue).onClick(() => {this.fontSizeValue = 30})}}
    }

使用场景

以下示例声明了3个Text组件,每个Text组件均设置了fontStyle、fontWeight和backgroundColor样式。

@Entry
@Component
struct FancyUse {@State label: string = 'Hello World'build() {Row({ space: 10 }) {Text(`${this.label}`).fontStyle(FontStyle.Italic).fontWeight(100).backgroundColor(Color.Blue)Text(`${this.label}`).fontStyle(FontStyle.Italic).fontWeight(200).backgroundColor(Color.Pink)Text(`${this.label}`).fontStyle(FontStyle.Italic).fontWeight(300).backgroundColor(Color.Orange)}.margin('20%')}
}

@Extend将样式组合复用,示例如下。

@Extend(Text) function fancyText(weightValue: number, color: Color) {.fontStyle(FontStyle.Italic).fontWeight(weightValue).backgroundColor(color)
}

通过@Extend组合样式后,使得代码更加简洁,增强可读性。

@Entry
@Component
struct FancyUse {@State label: string = 'Hello World'build() {Row({ space: 10 }) {Text(`${this.label}`).fancyText(100, Color.Blue)Text(`${this.label}`).fancyText(200, Color.Pink)Text(`${this.label}`).fancyText(300, Color.Orange)}.margin('20%')}
}

http://www.15wanjia.com/news/27112.html

相关文章:

  • 网站开发后台php技术今天宣布疫情最新消息
  • 广东省最新疫情防控信息seo基础知识培训视频
  • wordpress单本小说主题优化公司组织架构
  • 建设网站培训学校seo快排优化
  • 聊城网页设计公司seo结算系统
  • 潍坊智能建站模板运营培训班有用吗
  • 随州网站seo诊断软件培训机构哪家好
  • app开发需求文档模板什么是seo营销
  • 义乌购物网站建设多少钱一网信息一个简单便捷的新闻网站
  • 优推宝可以做自己网站吗深圳网站设计
  • 做二手房又做网站的广州百度推广电话
  • 做网站的相关术语推荐一个seo优化软件
  • 通州区住房和城乡建设部网站泰州seo推广
  • 企业网站的基本内容有哪些网页设计制作教程
  • 江西网站建设优化服务潍坊百度快速排名优化
  • 宁波比较好的外贸公司台州百度推广优化
  • 保定网站制作网页建网站的流程
  • WordPress 卡密购买插件seo建站工具
  • 手机wap网站模板 带后台深圳网络推广专员
  • 做网站用php还是html百度认证有什么用
  • 网站域名审核时间免费关键词排名优化
  • 深圳龙岗区吉华街道邮编宁波seo链接优化
  • 做棋牌网站多少钱seo外链在线提交工具
  • 小程序sdk开发seo新方法
  • 申请账号注册常用的seo查询工具
  • 做个卖车票的网站怎么做企业培训课程种类
  • 招聘网站建设销售seo网站关键词优化工具
  • 哪个网站做恒生指数最安全社群营销
  • 手机销售网站怎么做百度指数人群画像
  • 公司网站高端网站建设廊坊网站建设公司