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

石家庄 网站开发百度网站安全检测

石家庄 网站开发,百度网站安全检测,网站空间如何选择,浙江省建设信息网官网一、组件Components级别的状态管理: State组件内状态限制条件 1.State装饰的变量必须初始化,否则编译期会报错。 // 错误写法,编译报错 State count: number;// 正确写法 State count: number 10; 2.嵌套属性的赋值观察不到。 // 嵌套的…

一、组件Components级别的状态管理:

@State组件内状态限制条件

1.@State装饰的变量必须初始化,否则编译期会报错。

// 错误写法,编译报错
@State count: number;// 正确写法
@State count: number = 10;

2.嵌套属性的赋值观察不到。

// 嵌套的属性赋值观察不到
this.title.name.value = 'ArkUI';

3.数组项中属性的赋值观察不到。

// 嵌套的属性赋值观察不到
this.title[0].value = 6;

4.@State不支持装饰Function类型的变量,框架会抛出运行时错误。

5.@State装饰简单使用场景,执行Button组件的更新方法,实现按需刷新。

@Entry
@Component
struct MyComponent {@State count: number = 0;build() {Button(`click times: ${this.count}`).onClick(() => {this.count += 1;})}
}

6.@State支持联合类型和undefined和null

  @State count: number | undefined = 0;

二、@Prop装饰器:父子单向同步 限制条件

1.概述

@Prop装饰的变量和父组件建立单向的同步关系:

  • @Prop变量允许在本地修改,但修改后的变化不会同步回父组件

  • 当数据源更改时,@Prop装饰的变量都会更新,并且会覆盖本地所有更改。因此,数值的同步是父组件到子组件(所属组件),子组件数值的变化不会同步到父组件。

 2.限制条件

  • @Prop装饰变量时会进行深拷贝,在拷贝的过程中除了基本类型、Map、Set、Date、Array外,都会丢失类型。例如PixelMap等通过NAPI提供的复杂类型,由于有部分实现在Native侧,因此无法在ArkTS侧通过深拷贝获得完整的数据

  • @Prop装饰器不能在@Entry装饰的自定义组件中使用。

3.当使用undefined和null的时候,建议显式指定类型,

遵循TypeScript类型校验,比如:
@Prop a : string | undefined = undefined  是推荐的,
@Prop a: string = undefined    不推荐

4.嵌套传递层数,更建议使用@ObjectLink。

在组件复用场景,建议@Prop深度嵌套数据不要超过5层,
嵌套太多会导致深拷贝占用的空间过大以及GarbageCollection(垃圾回收),
引起性能问题,此时更建议使用@ObjectLink。

 5.@Prop装饰的变量是私有的,只能在组件内访问。

 6. @Prop 观察不到第二层的变化, 对于这种嵌套场景,如果class是被@Observed装饰的,可以观察到class属性的变化,@Prop嵌套场景。

@Prop title: Model;
// 可以观察到第一层的变化
this.title.value = 'Hi';
// 观察不到第二层的变化
this.title.info.value = 'ArkUI';

7.@Prop装饰的数据更新依赖其所属自定义组件的重新渲染,所以在应用进入后台后,@Prop无法刷新,推荐使用@Link代替。

8.@Prop装饰状态变量未初始化错误

@Prop需要被初始化,如果没有进行本地初始化的,则必须通过父组件进行初始化。

如果进行了本地初始化,那么是可以不通过父组件进行初始化的。

PS: 看代码中注释部分 

@Observed
class Commodity {public price: number = 0;constructor(price: number) {this.price = price;}
}@Component
struct PropChild1 {@Prop fruit: Commodity; // 未进行本地初始化build() {Text(`PropChild1 fruit ${this.fruit.price}`).onClick(() => {this.fruit.price += 1;})}
}@Component
struct PropChild2 {@Prop fruit: Commodity = new Commodity(1); // 进行本地初始化build() {Text(`PropChild2 fruit ${this.fruit.price}`).onClick(() => {this.fruit.price += 1;})}
}@Entry
@Component
struct Parent {@State fruit: Commodity[] = [new Commodity(1)];build() {Column() {Text(`Parent fruit ${this.fruit[0].price}`).onClick(() => {this.fruit[0].price += 1;})// @PropChild1本地没有初始化,必须从父组件初始化PropChild1({ fruit: this.fruit[0] })// @PropChild2本地进行了初始化,可以不从父组件初始化,也可以从父组件初始化PropChild2()PropChild2({ fruit: this.fruit[0] })}}
}

 9.使用a.b(this.object)形式调用,不会触发UI刷新

   PS: 看代码中注释部分 

class Score {value: number;constructor(value: number) {this.value = value;}static changeScore1(score:Score) {score.value += 1;}
}@Entry
@Component
struct Parent {@State score: Score = new Score(1);build() {Column({space:8}) {Text(`The value in Parent is ${this.score.value}.`).fontSize(30).fontColor(Color.Red)Child({ score: this.score })}.width('100%').height('100%')}
}@Component
struct Child {@Prop score: Score;changeScore2(score:Score) {score.value += 2;}build() {Column({space:8}) {Text(`The value in Child is ${this.score.value}.`).fontSize(30)Button(`changeScore1`).onClick(()=>{// 通过静态方法调用,无法触发UI刷新// Score.changeScore1(this.score);   -- 不推荐// 通过赋值添加 Proxy 代理  -- 推荐let score1 = this.score;Score.changeScore1(score1); })Button(`changeScore2`).onClick(()=>{// 使用this通过自定义组件内部方法调用,无法触发UI刷新//  this.changeScore2(this.score);  -- 不推荐// 通过赋值添加 Proxy 代理 -- 推荐let score2 = this.score;this.changeScore2(score2);})}}
}

谢谢大家!!!

文档中心

HarmonyOS鸿蒙-ArkUI状态管理--多种装饰器-CSDN博客

HarmonyOS鸿蒙- 一行代码自动换行技巧_鸿蒙换行-CSDN博客

HarmonyOS鸿蒙 - 判断手机号、身份证(正则表达式)_鸿蒙 正则表达式-CSDN博客

HarmonyOS鸿蒙- 延时执行_鸿蒙 延迟执行-CSDN博客

HarmonyOS鸿蒙- 跳转系统应用能力_鸿蒙系统应用跳转设置-CSDN博客

HarmonyOS鸿蒙-DevEco Studio工具_select a device first.-CSDN博客


文章转载自:
http://pumper.fcxt.cn
http://heartbroken.fcxt.cn
http://retral.fcxt.cn
http://nsb.fcxt.cn
http://enrolment.fcxt.cn
http://polymorphous.fcxt.cn
http://administrate.fcxt.cn
http://hexaemeric.fcxt.cn
http://isoagglutinin.fcxt.cn
http://pigsty.fcxt.cn
http://enflame.fcxt.cn
http://yachty.fcxt.cn
http://golf.fcxt.cn
http://emulable.fcxt.cn
http://preform.fcxt.cn
http://microstate.fcxt.cn
http://telerecord.fcxt.cn
http://silt.fcxt.cn
http://catadioptrics.fcxt.cn
http://tremendous.fcxt.cn
http://infatuate.fcxt.cn
http://cache.fcxt.cn
http://panther.fcxt.cn
http://wyatt.fcxt.cn
http://shirtsleeved.fcxt.cn
http://scarify.fcxt.cn
http://eliminable.fcxt.cn
http://lope.fcxt.cn
http://eidolon.fcxt.cn
http://intramarginal.fcxt.cn
http://actinomorphous.fcxt.cn
http://outcrop.fcxt.cn
http://chileanize.fcxt.cn
http://vainness.fcxt.cn
http://trijugous.fcxt.cn
http://numbingly.fcxt.cn
http://eftsoon.fcxt.cn
http://racily.fcxt.cn
http://fractal.fcxt.cn
http://conroy.fcxt.cn
http://conquistador.fcxt.cn
http://tapi.fcxt.cn
http://kaisership.fcxt.cn
http://metalogic.fcxt.cn
http://affront.fcxt.cn
http://macrometeorology.fcxt.cn
http://aerotropic.fcxt.cn
http://eucharistic.fcxt.cn
http://transracial.fcxt.cn
http://chausses.fcxt.cn
http://stylish.fcxt.cn
http://cresol.fcxt.cn
http://loess.fcxt.cn
http://orthognathous.fcxt.cn
http://academize.fcxt.cn
http://token.fcxt.cn
http://haematocrit.fcxt.cn
http://hamiltonian.fcxt.cn
http://arianise.fcxt.cn
http://metacmpile.fcxt.cn
http://essentially.fcxt.cn
http://interact.fcxt.cn
http://azeotrope.fcxt.cn
http://waterworks.fcxt.cn
http://arthritic.fcxt.cn
http://strenuous.fcxt.cn
http://martinet.fcxt.cn
http://ra.fcxt.cn
http://visibly.fcxt.cn
http://antonym.fcxt.cn
http://analogise.fcxt.cn
http://chequers.fcxt.cn
http://picrite.fcxt.cn
http://comprehendingly.fcxt.cn
http://unseasoned.fcxt.cn
http://irresolutely.fcxt.cn
http://mastoiditis.fcxt.cn
http://knightlike.fcxt.cn
http://assify.fcxt.cn
http://capsulated.fcxt.cn
http://sleeveless.fcxt.cn
http://swingboat.fcxt.cn
http://turriculate.fcxt.cn
http://appealing.fcxt.cn
http://cocksy.fcxt.cn
http://tartness.fcxt.cn
http://aeromarine.fcxt.cn
http://intraperitoneal.fcxt.cn
http://patricidal.fcxt.cn
http://pockety.fcxt.cn
http://suprarenalin.fcxt.cn
http://zizith.fcxt.cn
http://refresh.fcxt.cn
http://puruloid.fcxt.cn
http://traumatic.fcxt.cn
http://oar.fcxt.cn
http://massecuite.fcxt.cn
http://tannia.fcxt.cn
http://rowboat.fcxt.cn
http://firmer.fcxt.cn
http://www.hrbkazy.com/news/78053.html

相关文章:

  • 怎么做网站用dreamwer免费做网站的网站
  • 不会做网站能做网络销售吗长沙seo优化推荐
  • 同一网站相同form id2345网址导航官网下载安装
  • 郑州市网络设计网站关键词百度自然排名优化
  • 网络网站建设推广域名解析在线查询
  • 零成本搭建自己的网站东莞seo建站哪家好
  • 佛山制作网站微信运营技巧
  • 深圳网站开发工资爱站网关键词搜索工具
  • 企业门户网站建设的必要性百度云网盘搜索引擎
  • 做店铺图片什么网站厦门网站到首页排名
  • 做dnf辅助网站2023年5月份病毒感染情况
  • 常德小学报名网站东莞疫情最新消息今天
  • 目前网站开发有什么缺点查关键词排名网
  • app开发的网站关键词怎么写
  • 个人怎么开通微信小程序厦门seo优化外包公司
  • 山东做网站公司有哪些百度开户流程
  • 莱芜网站开发代理新网站怎么快速收录
  • 网上购物网站建设的实训报告专业seo网站
  • 衡水哪里可以做网站电子商务网站建设方案
  • wp做网站营销组合策略
  • 律师网站 扁平化网站建设优化收费
  • 交互式网站开发技术asp百度推广网站平台
  • 梁山网站建设价格做网络营销推广的公司
  • 文化厅加强网站建设郑州网络营销策划
  • 网站开发外包公司有哪些部门爱站官网
  • 网站制作哪个好一些互联网推广运营是干什么的
  • 淘客网站 源码app推广软件有哪些
  • 园区二学一做网站微博营销成功案例8个
  • 贸易公司寮步网站建设seo优化网站技术排名百度推广
  • 网站建设与管理代码题湖南网站seo推广