第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

鴻蒙Next自定義組件屬性訪(fǎng)問(wèn)限定符

鸿蒙Next开发中,ArkTS对自定义组件的成员变量使用的访问限定符private/public/protected有特定的校验规则,当不按规范使用时会产生相应的日志信息。

一、使用限制概述

(一)private修饰相关限制

  1. 对于@State/@Prop/@Provide/@BuilderParam/常规成员变量(不涉及更新的普通变量),使用private修饰时,在自定义组件构造时不允许进行赋值传参,否则会有编译告警日志提示。

(二)public修饰相关限制

  1. 对于@StorageLink/@StorageProp/@LocalStorageLink/@LocalStorageProp/@Consume变量,使用public修饰时,会有编译告警日志提示。

(三)private与特定装饰器同时修饰限制

  1. 对于@Link/@ObjectLink变量,使用private修饰时,会有编译告警日志提示。

(四)protected修饰限制

  1. 由于struct没有继承能力,所有上述变量使用protected修饰时,会有编译告警日志提示。

(五)@Require与private同时修饰限制

  1. 当@Require和private同时修饰自定义组件struct的@State/@Prop/@Provide/@BuilderParam/常规成员变量(不涉及更新的普通变量)时,会有编译告警日志提示。

二、错误使用场景示例

(一)private与@State/@Prop/@Provide/@BuilderParam同时修饰

  1. 代码示例
@Entry
@Component
struct AccessRestrictions {
  @Builder
  buildTest() {
    Text("Parent builder")
  }
  build() {
    Column() {
      ComponentsChild({
        state_value: "Hello",
        prop_value: "Hello",
        provide_value: "Hello",
        builder_value: this.buildTest,
        regular_value: "Hello"
      })
    }
  .width('100%')
  }
}
@Component
struct ComponentsChild {
  @State private state_value: string = "Hello";
  @Prop private prop_value: string = "Hello";
  @Provide private provide_value: string = "Hello";
  @BuilderParam private builder_value: () => void = this.buildTest;
  private regular_value: string = "Hello";
  @Builder
  buildTest() {
    Text("Child builder")
  }
  build() {
    Column() {
      Text("Hello")
      .fontSize(50)
      .fontWeight(FontWeight.Bold)
    }
  }
}
  1. 编译告警日志
    • Property’state_value’ is private and can not be initialized through the component constructor.
    • Property ‘prop_value’ is private and can not be initialized through the component constructor.
    • Property ‘provide_value’ is private and can not be initialized through the component constructor.
    • Property ‘builder_value’ is private and can not be initialized through the component constructor.
    • Property’regular_value’ is private and can not be initialized through the component constructor.

(二)public与@StorageLink/@StorageProp/@LocalStorageLink/@LocalStorageProp/@Consume同时修饰

  1. 代码示例
@Entry
@Component
struct AccessRestrictions {
  @Provide consume_value: string = "Hello";
  build() {
    Column() {
      ComponentChild()
    }
  .width('100%')
  }
}
@Component
struct ComponentChild {
  @LocalStorageProp("sessionLocalProp") public local_prop_value: string = "Hello";
  @LocalStorageLink("sessionLocalLink") public local_link_value: string = "Hello";
  @StorageProp("sessionProp") public storage_prop_value: string = "Hello";
  @StorageLink("sessionLink") public storage_link_value: string = "Hello";
  @Consume public consume_value: string;
  build() {
    Column() {
      Text("Hello")
      .fontSize(50)
      .fontWeight(FontWeight.Bold)
    }
  }
}
  1. 编译告警日志
    • Property ‘local_prop_value’ can not be decorated with both @LocalStorageProp and public.
    • Property ‘local_link_value’ can not be decorated with both @LocalStorageLink and public.
    • Property’storage_prop_value’ can not be decorated with both @StorageProp and public.
    • Property’storage_link_value’ can not be decorated with both @StorageLink and public.
    • Property ‘consume_value’ can not be decorated with both @Consume and public.

(三)private与@Link/@ObjectLink同时修饰

  1. 代码示例
@Entry
@Component
struct AccessRestrictions {
  @State link_value: string = "Hello";
  @State objectLink_value: ComponentObj = new ComponentObj();
  build() {
    Column() {
      ComponentChild({link_value: this.link_value, objectLink_value: this.objectLink_value})
    }
  .width('100%')
  }
}
@Observed
class ComponentObj {
  count: number = 0;
}
@Component
struct ComponentChild {
  @Link private link_value: string;
  @ObjectLink private objectLink_value: ComponentObj;
  build() {
    Column() {
      Text("Hello")
      .fontSize(50)
      .fontWeight(FontWeight.Bold)
    }
  }
}
  1. 编译告警日志
    • Property ‘link_value’ can not be decorated with both @Link and private.
    • Property ‘objectLink_value’ can not be decorated with both @ObjectLink and private.

(四)protected修饰

  1. 代码示例
@Entry
@Component
struct AccessRestrictions {
  build() {
    Column() {
      ComponentChild({regular_value: "Hello"})
    }
  .width('100%')
  }
}
@Component
struct ComponentChild {
  protected regular_value: string = "Hello";
  build() {
    Column() {
      Text("Hello")
      .fontSize(50)
      .fontWeight(FontWeight.Bold)
    }
  }
}
  1. 编译告警日志
    • The member attributes of a struct can not be protected.

(五)private、@Require与@State/@Prop/@Provide/@BuilderParam同时修饰

  1. 代码示例
@Entry
@Component
struct AccessRestrictions {
  build() {
    Column() {
      ComponentChild({prop_value: "Hello"})
    }
  .width('100%')
  }
}
@Component
struct ComponentChild {
  @Require @Prop private prop_value: string = "Hello";
  build() {
    Column() {
      Text("Hello")
      .fontSize(50)
      .fontWeight(FontWeight.Bold)
    }
  }
}
  1. 编译告警日志
    • Property ‘prop_value’ can not be decorated with both @Require and private.
    • Property ‘prop_value’ is private and can not be initialized through the component constructor.

开发者在使用鸿蒙Next自定义组件时,需遵循这些访问限定符的使用规则,避免因不规范使用而产生编译告警,确保组件的正确构建和功能实现。同时,注意这些规则从API version 12开始支持,在开发过程中要根据实际的API版本进行相应的处理。

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
移動(dòng)開(kāi)發(fā)工程師
手記
粉絲
0
獲贊與收藏
0

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫(xiě)下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶(hù)
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專(zhuān)欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消