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

风向 网站全国防疫大数据平台

风向 网站,全国防疫大数据平台,it培训学校,吉林省科瑞建设项目管理有限公司网站1.组件重用样式 如果每个组件的样式都需要单独设置#xff0c;在开发过程中会出现大量代码在进行重复样式设置#xff0c;虽然可以复制粘贴#xff0c;但为了代码简洁性和后续方便维护#xff0c;可以采用公共样式进行复用的装饰器Styles。 Styles装饰器可以将多条样式设置…1.组件重用样式 如果每个组件的样式都需要单独设置在开发过程中会出现大量代码在进行重复样式设置虽然可以复制粘贴但为了代码简洁性和后续方便维护可以采用公共样式进行复用的装饰器Styles。 Styles装饰器可以将多条样式设置提炼成一个方法直接在组件声明的位置调用。通过Styles装饰器可以快速定义并复用自定义样式。用于快速定义并复用自定义样式。 当前Styles仅支持[通用属性]和[通用事件]。  styles方法不支持参数 Styles可以定义在组件内或全局在全局定义时需在方法名前面添加function关键字组件内定义时则不需要添加function关键字。 注意: 组件内Styles的优先级高于全局Styles. 框架优先找当前组件内的Styles如果找不到则会全局查找。 Entry //入口 Component struct PageB_build_param {State message: string Hello World //State 数据改变了也刷新的标签State username: string State password: string State widths:number 90build() {Row() {Column() {text({ title: 用户, valueStr:this.username, cb: (value:string) {this.usernamevalue} })text({ title:密码,valueStr:this.password,cb:(value:string){this.passwordvalue} })Divider().margin(10)Row() {Button(登录).fontSize(16).myprivateStyle().margin({ right: 10, left: 10 }).onClick(this.login.bind(this))Button(重置).fontSize(16).myprivateStyle().margin({ left: 10, right: 10 }).onClick(this.reset.bind(this))}}.width(100%).height(50%)}.height(100%).width(100%)}Styles//提取共有的属性 在struct内myprivateStyle(){.width(this.widths).height(50)}//登录login() {console.log(this.username----this.password)}reset() {this.username this.password this.widths180} } Styles//全局样式 提取 function Mystyle(){.margin(10).padding(10).width(80).height(50).backgroundColor(#333333) }Builder //全局自定义构件函数 function text($$: { title: string,valueStr: string,cb: (value: string) void }) {Row() {Text($$.title).Mystyle().fontSize(16).fontColor(Color.White).textAlign(TextAlign.Center).border({width: 3,color: Color.Blue}).borderRadius(10).fontWeight(FontWeight.Bold)TextInput({ text: $$.valueStr }).width(200).height(50).fontSize(16).onChange((value: string) {$$.cb(value)})}.alignItems(VerticalAlign.Center)} 2.扩展组件样式 Extend(UIcomponentName) function functionName { ... } ·和Styles不同Extend仅支持定义在全局不支持在组件内部定义。 ·和Styles不同Extend支持封装指定的组件的私有属性和私有事件和预定义相同组件的Extend的方法。·和Styles不同Extend装饰的方法支持参数开发者可以在调用时传递参数调用遵循TS方法传值调用·Extend装饰的方法的参数可以为function作为Event事件的句柄。 Extend的参数可以为状态变量当状态变量改变时UI可以正常的被刷新渲染。 Extend(Text)//全局对组件-Text进行扩展 function MyTextExtend(text:string){.margin(10).padding(10).width(80).height(50).backgroundColor(text用户? #666666 : #333333).fontSize(16).fontColor(Color.White).textAlign(TextAlign.Center).border({width: 3,color: Color.Blue}).borderRadius(10).fontWeight(FontWeight.Bold) }Extend(TextInput)//对组件textinput进行扩展 function myTextInput(cb:(value :string ) void){.width(200).height(50).fontSize(16).onChange((value: string) {cb(value)}) }Builder //全局自定义构件函数 function text($$: { title: string,valueStr: string,cb: (value: string) void }) {Row() {Text($$.title).MyTextExtend($$.title)TextInput({ text: $$.valueStr }).myTextInput($$.cb)}.alignItems(VerticalAlign.Center) } 3.多态样式 stateStyles是属性方法可以根据UI内部状态来设置样式类似于css伪类但语法不同。ArkUI提供以 下四种状态: focused:获焦态。 normal: 正常态。 pressed: 按压态。 disabled: 不可用态。 Extend(TextInput)//对组件textinput进行扩展 function myTextInput(cb:(value :string ) void){.width(200).height(50).fontSize(16).stateStyles({normal:normalStyle,pressed:pressStyle,focused:foucsStyle}).onChange((value: string) {cb(value)}) } Styles function pressStyle(){.backgroundColor(Color.White) } Styles function foucsStyle(){.backgroundColor(Color.Red) } Styles function normalStyle(){.backgroundColor(Color.Green) }4.循环渲染 ForEach( arr: Array, itemGenerator: (item: any, index?: number) void, keyGenerator?: (item: any index?: number): string string ) 在ForEach循环渲染过程中系统会为每个数组元素生成一个唯一且持久的键值 用于标识对应的组件。当这个键值变化时ArkUI框架将视为该数组元素已被替换或修改,并会基于新的键值创建一个新的组件。 ForEach提供了一个名为keyGenerator的参数,这是一个函数,开发者可以通过它自定义键值的生成规则。如果开发者没有定义keyGenerator函数则ArkUI框架会使用默认的键值生成函数即(item: any, index: number) { return index _ JSON.stringify(item); }。 Entry Component struct PageForEach {State list: string [] [Hello World, hello harmonyos, hello my]State list1: Object [] [{ id: 1, name: 房子 }, { id: 2, name: 车子 }, { id: 3, name: 票子 }]build() {Row() {Column() {ForEach(this.list, (item: string) {Text(item).fontSize(26)})ForEach(this.list1, (item1: Object) {Text(item1[name]).fontSize(26)},itemJSON.stringify(item))//用这个去作为唯一的key// List组件配合 ForEach超出屏幕可以滚动List(){ForEach(this.list1,(item1:Object){ListItem(){Text(item1[name]).fontSize(26).margin(10)}},itemJSON.stringify(item))}.height(60).divider({startMargin:10,endMargin:10,strokeWidth:1,color:Color.Green})Button(切换).onClick((){this.list1[1][name]银山this.list1.splice(0,1,{id:1,name:金山})})}.width(100%)}.height(100%)} }
http://www.pierceye.com/news/685244/

相关文章:

  • 个人个案网站 类型wordpress群组
  • 微网站建设深圳英文站seo
  • 做网站要钱么网站建设备案多长时间
  • wordpress建站图片效果网站备案前置审批 成都
  • 哈尔滨网站关键词优化手机网站视频播放模板
  • 西安企业做网站贵州毕节建设局网站官网
  • 临沂网站定制室内设计师证书哪个含金量高
  • 国外做化工产品的网站湛江手机网站建设公司
  • 企业网站管理系统如何上传图片湖南网站建设营销推广
  • 网站建设衤金手指花总十五开发平台和开发工具
  • 免费网站安全软件大全游戏网络规划设计师资料及视频教程
  • 怎么把电脑网站做服务器吗做网站的回扣
  • 无锡模板网站设计公司中介网站设计
  • 微网站 手机网站html做一个学校网页
  • 重庆建设工程招标网站电商网站需要哪些备案
  • 有关网页设计与网站建设的文章崇信门户网站留言回复
  • 网站优化有哪些技巧对网站建设的建议
  • wordpress网站管理系统室内设计公司有哪些
  • 域名购买网站个人怎么在百度上打广告
  • 阳江市建设路龙源学校网站物流公司 网站模板
  • 迪庆州建设局网站做营销网站建设挣钱吗
  • 定制网站类似wordpress 简单
  • 数据库对于做网站的重要性商城模板网站模板
  • 梧州高端网站建设服务企业网站建设源码
  • 团购网站优化德州seo排名
  • 网站首页引导页中文简洁网站设计图
  • 娱乐网站排行榜在线商城网站开发代码
  • 手机网站设计通用尺寸上海外贸人才网
  • 智慧团建网站密码格式高端终端网站设计类网站
  • 福田网站设计网站建设平台方案