HarmonyOS @ComponentV2装饰的自定义组件暂不支持组件复用

@ComponentV2装饰的自定义组件暂不支持组件复用,具体是什么含义?

HarmonyOS
2025-01-09 13:35:50
725浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

可以为@Component装饰的组件添加@Reusable注解使自定义组件具备可复用能力。但是@ComponentV2无法添加@Reusable,参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-create-custom-components-V5#自定义组件的基本结构

参考下列示例,会报错:

@Entry
@Reusable
@ComponentV2
struct Index {
  //@State message: string = 'Hello World';

  build() {
    RelativeContainer() {
      Text(this.message)
        .id('HelloWorld')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
    }
    .height('100%')
    .width('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
分享
微博
QQ
微信
回复
2025-01-09 16:26:29


相关问题
HarmonyOS @ComponentV2修饰组件一些问题
505浏览 • 1回复 待解决
CustomDialog不支持自定义动画
1065浏览 • 2回复 待解决
HarmonyOS @ComponentV2使用暗黑会崩溃
502浏览 • 1回复 待解决
HarmonyOS 弱引用不支持自定义对象吗
637浏览 • 1回复 待解决
web组件不支持localstorage
1304浏览 • 1回复 待解决
是否支持自定义装饰
2626浏览 • 1回复 待解决
HarmonyOS 是否支持自定义装饰器?
813浏览 • 1回复 待解决
HarmonyOS RNOH Image组件不支持apng
517浏览 • 1回复 待解决
恭喜您,今日已阅读两篇内容,特奖励+2声望, 快来领取吧。