范文健康探索娱乐情感热点
投稿投诉
热点动态
科技财经
情感日志
励志美文
娱乐时尚
游戏搞笑
探索旅游
历史星座
健康养生
美丽育儿
范文作文
教案论文
国学影视

鸿蒙HarmonyOSArkUI(eTS)组件通信方式总结之四祖孙组件间1

  鸿蒙HarmonyOS ArkUI(eTS)组件间通信涉及组件属性与显示、父子组件间通信、祖孙组件间通信、不相干组件间通信等,而组件两两间通信也有单向与双向之分。通过学习HDC2021和官方文档,本系列以@State、@Link、@Prop、@Provide与@Consume、@StorageLink等组件状态装饰器介绍组件间通信方式。
  本次介绍:祖孙组件间通信方式之一@State、@Link、@Prop。
  1.父组件@State,子组件@Link,孙组件@Link
  数据流向是: 父组件  <-->  子组件  <-->  孙组件  @Entry @Component struct Index {   @State fatherVal: number = 0    build() {     Column(){       Text(`父组件: ${this.fatherVal}`)         .fontSize(50)         .fontWeight(FontWeight.Bold)         .margin({top: 30})       Row(){         Button("加 1")           .width("100")           .onClick(()=> {             this.fatherVal ++           })           .margin({right:20})         Button("减 1")           .width("100")           .onClick(()=> {             this.fatherVal --           })       }       .margin({bottom: 20})       Divider()       subIndex({sonVal: $fatherVal})     }     .width("100%")     .height("100%")     .backgroundColor(Color.Pink)   } }  //子组件 @Component struct subIndex {   @Link sonVal: number    build(){     Column(){       Text(`子组件: ${this.sonVal}`)         .fontSize(40)         .fontWeight(FontWeight.Bold)         .margin({top: 30})       Row(){         Button("加 1")           .width("100")           .onClick(()=> {             this.sonVal ++           })           .margin({right:20})         Button("减 1")           .width("100")           .onClick(()=> {             this.sonVal --           })       }       .margin({bottom: 20})       Divider()       grandsonIndex({grandsonVal: $sonVal})     }     .width("90%")     .backgroundColor(Color.Orange)   } } //孙组件 @Component struct grandsonIndex {   @Link grandsonVal: number    build(){     Column(){       Text(`孙组件: ${this.grandsonVal}`)         .fontSize(30)         .fontWeight(FontWeight.Bold)         .margin({top: 30})       Row(){         Button("加 1")           .width("100")           .onClick(()=> {             this.grandsonVal ++           })           .margin({right:20})         Button("减 1")           .width("100")           .onClick(()=> {             this.grandsonVal --           })       }     }     .width("80%")     .backgroundColor(Color.Brown)   } }
  2.父组件@State,子组件@Prop,孙组件@Prop
  数据流向是:父组件 --> 子组件 --> 孙组件 @Entry @Component struct Index {   @State fatherVal: number = 0    build() {     Column(){       Text(`父组件: ${this.fatherVal}`)         .fontSize(50)         .fontWeight(FontWeight.Bold)         .margin({top: 30})       Row(){         Button("加 1")           .width("100")           .onClick(()=> {             this.fatherVal ++           })           .margin({right:20})         Button("减 1")           .width("100")           .onClick(()=> {             this.fatherVal --           })       }       .margin({bottom: 20})       Divider()       subIndex({sonVal: this.fatherVal})     }     .width("100%")     .height("100%")     .backgroundColor(Color.Pink)   } }  //子组件 @Component struct subIndex {   @Prop sonVal: number    build(){     Column(){       Text(`子组件: ${this.sonVal}`)         .fontSize(40)         .fontWeight(FontWeight.Bold)         .margin({top: 30})       Row(){         Button("加 1")           .width("100")           .onClick(()=> {             this.sonVal ++           })           .margin({right:20})         Button("减 1")           .width("100")           .onClick(()=> {             this.sonVal --           })       }       .margin({bottom: 20})       Divider()       grandsonIndex({grandsonVal: this.sonVal})     }     .width("90%")     .backgroundColor(Color.Orange)   } } //孙组件 @Component struct grandsonIndex {   @Prop grandsonVal: number    build(){     Column(){       Text(`孙组件: ${this.grandsonVal}`)         .fontSize(30)         .fontWeight(FontWeight.Bold)         .margin({top: 30})       Row(){         Button("加 1")           .width("100")           .onClick(()=> {             this.grandsonVal ++           })           .margin({right:20})         Button("减 1")           .width("100")           .onClick(()=> {             this.grandsonVal --           })       }     }     .width("80%")     .backgroundColor(Color.Brown)   } }
  3.父组件@State,子组件@Link,孙组件@Prop
  数据流向是:父组件 <--> 子组件 --> 孙组件 @Entry @Component struct Index {   @State fatherVal: number = 0    build() {     Column(){       Text(`父组件: ${this.fatherVal}`)         .fontSize(50)         .fontWeight(FontWeight.Bold)         .margin({top: 30})       Row(){         Button("加 1")           .width("100")           .onClick(()=> {             this.fatherVal ++           })           .margin({right:20})         Button("减 1")           .width("100")           .onClick(()=> {             this.fatherVal --           })       }       .margin({bottom: 20})       Divider()       subIndex({sonVal: $fatherVal})     }     .width("100%")     .height("100%")     .backgroundColor(Color.Pink)   } }  //子组件 @Component struct subIndex {   @Link sonVal: number    build(){     Column(){       Text(`子组件: ${this.sonVal}`)         .fontSize(40)         .fontWeight(FontWeight.Bold)         .margin({top: 30})       Row(){         Button("加 1")           .width("100")           .onClick(()=> {             this.sonVal ++           })           .margin({right:20})         Button("减 1")           .width("100")           .onClick(()=> {             this.sonVal --           })       }       .margin({bottom: 20})       Divider()       grandsonIndex({grandsonVal: this.sonVal})     }     .width("90%")     .backgroundColor(Color.Orange)   } } //孙组件 @Component struct grandsonIndex {   @Prop grandsonVal: number    build(){     Column(){       Text(`孙组件: ${this.grandsonVal}`)         .fontSize(30)         .fontWeight(FontWeight.Bold)         .margin({top: 30})       Row(){         Button("加 1")           .width("100")           .onClick(()=> {             this.grandsonVal ++           })           .margin({right:20})         Button("减 1")           .width("100")           .onClick(()=> {             this.grandsonVal --           })       }     }     .width("80%")     .backgroundColor(Color.Brown)   } }
  不存在父组件@State、子组件@Prop、孙组件@Link这种情况,因为子组件中@Prop装饰的变量不能赋给孙组件中@Link装饰的变量。如果想达到以下数据流向:父组件 --> 子组件 <--> 孙组件,可采用以下方式实现:  @Entry @Component struct Index {   fatherVal: number = 6   @State fatherVal2: number = this.fatherVal    build() {     Column(){       Text(`父组件: ${this.fatherVal2}`)         .fontSize(50)         .fontWeight(FontWeight.Bold)         .margin({top: 30})       Row(){         Button("加 1")           .width("100")           .onClick(()=> {             this.fatherVal2 ++             this.fatherVal ++           })           .margin({right:20})         Button("减 1")           .width("100")           .onClick(()=> {             this.fatherVal2 --             this.fatherVal --           })       }       .margin({bottom: 20})       Divider()       subIndex({sonVal: this.fatherVal})     }     .width("100%")     .height("100%")     .backgroundColor(Color.Pink)   } }  //子组件 @Component struct subIndex {   @State sonVal: number = 0    build(){     Column(){       Text(`子组件: ${this.sonVal}`)         .fontSize(40)         .fontWeight(FontWeight.Bold)         .margin({top: 30})       Row(){         Button("加 1")           .width("100")           .onClick(()=> {             this.sonVal ++           })           .margin({right:20})         Button("减 1")           .width("100")           .onClick(()=> {             this.sonVal --           })       }       .margin({bottom: 20})       Divider()       grandsonIndex({grandsonVal: $sonVal})     }     .width("90%")     .backgroundColor(Color.Orange)   } } //孙组件 @Component struct grandsonIndex {   @Link grandsonVal: number    build(){     Column(){       Text(`孙组件: ${this.grandsonVal}`)         .fontSize(30)         .fontWeight(FontWeight.Bold)         .margin({top: 30})       Row(){         Button("加 1")           .width("100")           .onClick(()=> {             this.grandsonVal ++           })           .margin({right:20})         Button("减 1")           .width("100")           .onClick(()=> {             this.grandsonVal --           })       }     }     .width("80%")     .backgroundColor(Color.Brown)   } }

苹果遭到围剿,又一张巨额罚单即将落下,苹果税大势已去文JING审核子扬校对知秋苹果税是指苹果公司对于AppStore内收费应用都会抽成30的行为,按照苹果说法,之所以收取这部分费用,是因为消费者在收费应用消费时,使用了苹果内置支付系三只松鼠广告为何被广泛争议?国人缺乏的是否是自信?三只松鼠股份有限公司成立于2012年2月16日,是中国第一家定位于纯互联网食品品牌的企业,也是目前中国销售规模最大的电商企业,主要产品包括坚果,肉脯,果干,膨化等全品类休闲零食。三诺基亚新7360渲染图让苹果寝食难安,3枚2亿相机2TB存储诺基亚手机辉煌的时代,发布了多款型号的机型,并且有很多机型大家都耳熟能详。但是诺基亚手机品牌的没落,也让手机厂商看到失败的原因,因为一招不慎满盘皆输。实际上诺基亚手机想要重新崛起也2021一台让我愿意带出门的相机,自购SONYA7C全画幅微单体验本内容来源于什么值得买APP,观点仅代表作者本人作者兔牙先生大家好呀,我是兔牙先生。热爱咖啡,从事咖啡,但我依然是一只值得买的数码领域生活家。默默在值得买灌水8年了,2021年末,2022年空调业迎来拐点传统空调已成为过去唯有新风成行业共识蓝科技观察从价格战到价值战,从需要空调到需要健康空调,2022年的中国空调业或迎来拐点。随着人们生活水平的提高,仅有制冷制热功能的传统空调早已无法满足用户需求。行业内成达的共识是,小米手机MIUI系统必须打开的4个功能,每一个都很强大,红米通用本文编辑今日头条作者小俊技术分享未经授权严禁转载,发现抄袭者将进行全网投诉分享生活小妙招,享受科技新生活!大家好,欢迎来到今天的知识分享!我是你们的好朋友小俊!在MIUI系统中有非空气净化器和具有新风净化功能的空调买哪个更好空气净化器和具有新风净化功能的空调,买哪个更好呢?空调企业以空调为平台,将新风净化功能纳入到空调中,因此诞生了具有新风净化能力的空调,一个全面改善空气质量的新品类。空气净化器可加湿打个顺风车显示无拼友,上车后却有拼友?怎么办?司机该被投诉吗?车上有你的座位就行了。车主不允许带亲戚朋友,只能带你?不用纠结了,该投诉就投诉啊?各位把顺风车当专车坐的各位大爷们。重庆已经专门立法禁止私家车跑顺风车了,所以你们还是坐回自己的大巴想买台折叠屏,预算一万以下,有没有懂的人推荐一下?在折叠屏手机上,如今小米oppo华为三星摩托罗拉都有机型!最便宜的是OPPOFindN售价7699元,是横向折叠屏的手机!所以想要购买折叠屏手机,如今在折叠屏形式上要做一个抉择,一说吧,瞒着家里欠了多少?加起来80多万。1网贷目前有5个,网商贷5万3000元,花呗3万1500元,顺丰金融6万(目前还有5万多),360借钱7万2800元,翼支付2万多。现在只有网商贷花呗顺丰金融每个月一部手机正常能用几年?出现以下任意一种现象,代表该换机了一台手机的寿命是多久?其实很少人给出确切的答案,但我相信大家都希望自己买的大旗舰能顶用个三五年。各价位手机性能的区别也决定了它的寿命长度,如果出现以下四种现象任意一种,那么你该换手
面试官连这些问题都不知道?就想要50k?前言本人2016年毕业,目前从事Android开发工作已经3年啦。就是尘世间一个迷途小开发,二流程序员,居身于小城市,最终也是考虑到发展前景的局限性,趁着自己还年轻,于是毅然裸辞,相互宝关停的背后编辑导语近日,相互宝宣布将于2022年关停,因为这一消息,业内关于互联网互助平台的发展又展开了新一轮的讨论。为什么互联网互助平台的发展总是容易遇到商业变现上的困难?本文作者结合自己英特尔道歉,华为鸿蒙汽车问世!国产CPU的出路国产品牌一度崛起,我们的眼里只有国家的物品,国产我们一直都知道很好用,又很实惠。但是呢,总有一个搅屎棍英特尔。英特尔公司它要求供应商不要使用我们新疆的产品,英特尔这又是遭受了什么委华为Mate50Pro开始发力华为作为相当优秀的国产手机品牌,因为强悍的实力,优秀的品质,深受国内外用户欢迎。如果没有被制裁,华为将成为全球最受欢迎的手机厂商,市场占有率将会大大提升,全面超越三星和苹果。不过事望眼欲穿,iphoneSE3要来了,搭载A15处理器,支持5G网络自2020年4月15日发布iphoneSE2后,果粉们整整等了1年,iphoneSE3还是没有出现。苹果的SE系列机型机身小巧,价格实在,性能强悍,很受小屏爱好者的青睐。iPhon36氪首发从SDWAN延展到安全运维业务,七云网络完成数千万元的A轮融资36氪获悉,SDWAN及网络运维解决方案服务商七云网络已于日前完成A轮融资。本轮融资金额在数千万元级别,由维思资本领投,老股东常春藤资本和炬成资本继续加码,毅仁资本担任独家财务顾问判断是否装了QQ判断是否装了QQpublicstaticbooleanisQQClientAvailable(Contextcontext)finalPackageManagerpackageMa打造2万亿电商平台,马云却预言新零售会替代电商,提前投资700亿现如今,随着懒人经济的崛起,网上购物已经成了大家买东西的主要方式,而之所以可以享受这一方式,主要就是靠着马云花费2万亿打造的电商平台。值得注意的是,近两年马云又将目光放到了新零售领为什么很多人买手机只关注高端旗舰机?为什么有些人要买贵手机在买手机这件事上,买贵的手机是如何定义的,我觉得应该是这么理解,为什么很多人买手机只关注高端旗舰机。或者只看苹果手机,或者只看华为手机!因为这些手机价格都基本网站如何识别爬虫来访作为网站管理者,本着对网站数据客观详实的原则,是需要把爬虫带来的问题及时修复掉的,那核心问题就是网站如何识别爬虫来访?识别方案获取网页请求的useragent信息,使用特定标识判断互联网2021作者李好零九编辑钊岁末已至,是结束也是开始。2021年互联网圈的那些大事件,你还记得吗?反垄断社区团购广告行业增速放缓直播带货主播被罚刚送走庚子年的疫情,互联网行业还是没能继续大放