HarmonyOS鸿蒙Next中OpenHarmony @Builder BUG

HarmonyOS鸿蒙Next中OpenHarmony @Builder BUG

cke_441.png

加断点调试发现:

BUG: 用@Builder,只要TabBarContent的状态有变化,Setting就会重新创建(我不想重建组件),

但是直接用Setting就不会重新创建


更多关于HarmonyOS鸿蒙Next中OpenHarmony @Builder BUG的实战教程也可以访问 https://www.itying.com/category-93-b0.html

7 回复

楼主您好,已反馈给开发人员,请耐心等待,感谢您的支持

更多关于HarmonyOS鸿蒙Next中OpenHarmony @Builder BUG的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


楼主您好,经技术人员反馈,此问题是旧BUG,新框架已修复

楼主您好,请提供一下SDK版本号

# OpenHarmony API9 3.2.10.6 Beta5

- **版本**:
- **描述**:
- **更新时间**:

DEMO:

this.build_InstallDemo(),点击红色区域,时间已经改变组件被重建,这是错误的。

this.build_InstallDemo()换成InstallDemo(),点击红色区域,时间没有改变,组件没有重建,这是正确的。

看图:

cke_3490.png

代码:

@Entry @Component struct IndexPage { build() { Stack() { Demo(){ this.build_InstallDemo()// InstallDemo() } } } @Builder build_InstallDemo(){ InstallDemo(); } } @Component struct InstallDemo { build() { Text(this.getTime()); } getTime():string { return “我应该是不变的:”+new Date().getTime(); } aboutToAppear() { console.log(“我被重建了”) } } @Component struct Demo { @State count:number = 1; @BuilderParam content:() => void; build() { Column() { this.content() Text(“点击我,Count is:”+this.count) .width(100) .width(100) .backgroundColor(’#f00’) .onClick(()=>{ this.count++; }) } } }

可想而知,@Builder是严重影响性能的,而且有BUG

在HarmonyOS鸿蒙Next中,使用OpenHarmony的@Builder装饰器时,可能会遇到一些BUG,如组件渲染异常、状态管理失效等问题。这些问题通常与框架的版本兼容性或代码实现有关。建议检查以下几点:

  1. 确保使用最新版本的OpenHarmony SDK;

  2. 检查@Builder中的逻辑,避免异步操作或副作用;

  3. 使用@State@Link正确管理组件状态。

如问题持续,可参考官方文档或提交Issue到OpenHarmony社区。

回到顶部