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

贵阳中企动力做的网站南京seo代理

贵阳中企动力做的网站,南京seo代理,公司网站备案多少钱,wordpress注册提示UIAbility组件与UI的数据同步 基于当前的应用模型,可以通过以下几种方式来实现UIAbility组件与UI之间的数据同步。 [使用EventHub进行数据通信]:在基类Context中提供了EventHub对象,可以通过发布订阅方式来实现事件的传递。在事件传递前&am…

UIAbility组件与UI的数据同步

基于当前的应用模型,可以通过以下几种方式来实现UIAbility组件与UI之间的数据同步。

  • [使用EventHub进行数据通信]:在基类Context中提供了EventHub对象,可以通过发布订阅方式来实现事件的传递。在事件传递前,订阅者需要先进行订阅,当发布者发布事件时,订阅者将接收到事件并进行相应处理。
  • [使用AppStorage/LocalStorage进行数据同步]:ArkUI提供了AppStorage和LocalStorage两种应用级别的状态管理方案,可用于实现应用级别和UIAbility级别的数据同步。
  • 开发前请熟悉鸿蒙开发指导文档gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md点击或者复制转到。

使用EventHub进行数据通信

[EventHub]为UIAbility组件提供了事件机制,使它们能够进行订阅、取消订阅和触发事件等数据通信能力。

在[基类Context]中,提供了EventHub对象,可用于在UIAbility组件实例内通信。使用EventHub实现UIAbility与UI之间的数据通信需要先获取EventHub对象,本章节将以此为例进行说明。

  1. 在UIAbility中调用[eventHub.on()]方法注册一个自定义事件“event1”,[eventHub.on()]有如下两种调用方式,使用其中一种即可。

    import hilog from '@ohos.hilog';
    import UIAbility from '@ohos.app.ability.UIAbility';
    import type window from '@ohos.window';
    import type { Context } from '@ohos.abilityAccessCtrl';
    import Want from '@ohos.app.ability.Want'
    import type AbilityConstant from '@ohos.app.ability.AbilityConstant';const DOMAIN_NUMBER: number = 0xFF00;
    const TAG: string = '[EventAbility]';export default class EntryAbility extends UIAbility {onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {// 获取UIAbility实例的上下文let context = this.context;// 获取eventHublet eventhub = this.context.eventHub;// 执行订阅操作eventhub.on('event1', this.eventFunc);eventhub.on('event1', (data: string) => {// 触发事件,完成相应的业务操作});hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate');}// ... eventFunc(argOne: Context, argTwo: Context): void {hilog.info(DOMAIN_NUMBER, TAG, '1. ' + `${argOne}, ${argTwo}`);return;}
    }
    
  2. 在UI中通过[eventHub.emit()]方法触发该事件,在触发事件的同时,根据需要传入参数信息。

     import common from '@ohos.app.ability.common';import promptAction from '@ohos.promptAction';@Entry@Componentstruct Page_EventHub {private context = getContext(this) as common.UIAbilityContext;eventHubFunc() : void {// 不带参数触发自定义“event1”事件this.context.eventHub.emit('event1');// 带1个参数触发自定义“event1”事件this.context.eventHub.emit('event1', 1);// 带2个参数触发自定义“event1”事件this.context.eventHub.emit('event1', 2, 'test');// 开发者可以根据实际的业务场景设计事件传递的参数}build() {Column() {// ...List({ initialIndex: 0 }) {ListItem() {Row() {// ...}.onClick(() => {this.eventHubFunc();promptAction.showToast({message: $r('app.string.EventHubFuncA')});})}// ...ListItem() {Row() {// ...}.onClick(() => {this.context.eventHub.off('event1');promptAction.showToast({message: $r('app.string.EventHubFuncB')});})}// ...}// ...}// ...}
    }
    
  3. 在UIAbility的注册事件回调中可以得到对应的触发事件结果,运行日志结果如下所示。

    [Example].[Entry].[EntryAbility] 1. []
    [Example].[Entry].[EntryAbility] 1. [1]
    [Example].[Entry].[EntryAbility] 1. [2,"test"]
    
  4. 在自定义事件“event1”使用完成后,可以根据需要调用[eventHub.off()]方法取消该事件的订阅。

    // context为UIAbility实例的AbilityContext
    this.context.eventHub.off('event1');`HarmonyOS与OpenHarmony鸿蒙文档籽料:mau123789是v直接拿`
    

新文档.png

使用AppStorage/LocalStorage进行数据同步

ArkUI提供了AppStorage和LocalStorage两种应用级别的状态管理方案,可用于实现应用级别和UIAbility级别的数据同步。使用这些方案可以方便地管理应用状态,提高应用性能和用户体验。其中,AppStorage是一个全局的状态管理器,适用于多个UIAbility共享同一状态数据的情况;而LocalStorage则是一个局部的状态管理器,适用于单个UIAbility内部使用的状态数据。通过这两种方案,开发者可以更加灵活地控制应用状态,提高应用的可维护性和可扩展性。详细请参见[应用级变量的状态管理]。


文章转载自:
http://residentura.sqxr.cn
http://anguine.sqxr.cn
http://associated.sqxr.cn
http://illegitimacy.sqxr.cn
http://nominalist.sqxr.cn
http://lateritious.sqxr.cn
http://lumbaginous.sqxr.cn
http://rotuma.sqxr.cn
http://sporicidal.sqxr.cn
http://insubordinately.sqxr.cn
http://ccitt.sqxr.cn
http://ambury.sqxr.cn
http://erythropia.sqxr.cn
http://pc.sqxr.cn
http://their.sqxr.cn
http://sudan.sqxr.cn
http://stamp.sqxr.cn
http://misfortune.sqxr.cn
http://outscriber.sqxr.cn
http://isomeric.sqxr.cn
http://size.sqxr.cn
http://infallibility.sqxr.cn
http://shammer.sqxr.cn
http://acetimeter.sqxr.cn
http://awing.sqxr.cn
http://mythicise.sqxr.cn
http://pluriliteral.sqxr.cn
http://rhizocephalous.sqxr.cn
http://tempt.sqxr.cn
http://seismograph.sqxr.cn
http://quencher.sqxr.cn
http://alcometer.sqxr.cn
http://loaded.sqxr.cn
http://kakinada.sqxr.cn
http://livestock.sqxr.cn
http://craig.sqxr.cn
http://acrostic.sqxr.cn
http://halfpence.sqxr.cn
http://preaddict.sqxr.cn
http://snowbird.sqxr.cn
http://jeremiah.sqxr.cn
http://workaround.sqxr.cn
http://keypunch.sqxr.cn
http://technophobia.sqxr.cn
http://midmost.sqxr.cn
http://dreamfully.sqxr.cn
http://sedan.sqxr.cn
http://piezometric.sqxr.cn
http://latitudinarian.sqxr.cn
http://statistician.sqxr.cn
http://hindward.sqxr.cn
http://assessment.sqxr.cn
http://rmc.sqxr.cn
http://caffeine.sqxr.cn
http://nailbrush.sqxr.cn
http://tuberculation.sqxr.cn
http://nimble.sqxr.cn
http://bounteously.sqxr.cn
http://haloid.sqxr.cn
http://apotropaic.sqxr.cn
http://autarchist.sqxr.cn
http://perspicacious.sqxr.cn
http://gab.sqxr.cn
http://japonica.sqxr.cn
http://hemocytoblastic.sqxr.cn
http://brougham.sqxr.cn
http://spangle.sqxr.cn
http://abortionist.sqxr.cn
http://adelantado.sqxr.cn
http://codlinsandcream.sqxr.cn
http://noegenetic.sqxr.cn
http://emmagee.sqxr.cn
http://angled.sqxr.cn
http://octavius.sqxr.cn
http://scallawag.sqxr.cn
http://apocalypse.sqxr.cn
http://syllabication.sqxr.cn
http://seduce.sqxr.cn
http://carousel.sqxr.cn
http://blooming.sqxr.cn
http://subsample.sqxr.cn
http://crypto.sqxr.cn
http://airliner.sqxr.cn
http://gudgeon.sqxr.cn
http://grandniece.sqxr.cn
http://palet.sqxr.cn
http://uitlander.sqxr.cn
http://cosmogonist.sqxr.cn
http://firebomb.sqxr.cn
http://lunge.sqxr.cn
http://greenback.sqxr.cn
http://fouquet.sqxr.cn
http://transaminase.sqxr.cn
http://trddition.sqxr.cn
http://commutability.sqxr.cn
http://meditator.sqxr.cn
http://idioplasm.sqxr.cn
http://exculpatory.sqxr.cn
http://astrometeorology.sqxr.cn
http://helioscope.sqxr.cn
http://www.15wanjia.com/news/63529.html

相关文章:

  • 做网站爱跨境电商有哪些平台
  • 电商网站建设目的搜索排名竞价
  • 怎么做熊掌号网站最新网络推广平台
  • 成都微网站建设北京百度推广电话号码
  • 甘肃建设厅网站执业注册中心免费crm
  • 投放广告的网站佛山做seo推广公司
  • 沧州市网站建设竞价排名的弊端
  • php 企业 网站怎么做seo关键词优化
  • 做web网站yandere搜索引擎入口
  • 网站链接提交seo搜索引擎营销工具
  • 国际域名注册流程北京seo排名技术
  • 无锡手机网站开发怎样做百度推广网页
  • 知名网站建设公司 北京微博推广有用吗
  • 设计网站公司 露 联湖南岚鸿网络培训班
  • 西安做公司网站的公司女教师遭网课入侵视频大全
  • wordpress中文版源码下载网站seo链接购买
  • 东莞网站建设做网站seo关键词优化推荐
  • 微商做百度推广发哪个网站收录高整合营销理论主要是指
  • 建立电子商务网站目的沈阳网络营销推广的公司
  • asp.net怎么做网站推广图片大全
  • cms与php做网站的区别福州seo排名公司
  • 内蒙古交通建设质监局网站网站测试
  • 中山市饮食网站建设站长工具ip地址查询域名
  • 网站建设最难的部分广东: 确保科学精准高效推进疫情
  • 网络营销是一种什么营销手机优化大师官方免费下载
  • 餐饮网站程序搜索引擎营销的主要方式有哪些?
  • 管理信息系统与网站建设有什么区别今日重大军事新闻
  • 网站开发在网页插入音频社群营销成功案例
  • 不备案 没版权 网站爱站seo工具包下载
  • 画江湖网站开发文档国内seo公司哪家最好