HarmonyOS 自定义builder方法, 参数是按引用传递, 当状态值修改时, 不触发builder方法, 不会刷新UI

点击clickme时, 希望text的值变为overBuilder===ArkUI。

@Builder  
function overBuilder($$: string) {  
  Row() {  
    Column() {  
      Text(`overBuilder===${$$}`)  
    }  
  }  
}  
  
@Entry  
@Component  
struct Parent {  
  @State label: string = 'Hello';  
  
  build() {  
    Column() {  
      Button('Click me').onClick(() => {  
        this.label = 'ArkUI';  
      })  
      overBuilder(this.label)  
    }  
  }  
}
HarmonyOS
2024-09-27 11:25:25
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

demo如下:

class Tmp {  
  paramA1: string = ''  
}  
  
@Builder function overBuilder(params: Tmp) {  
  Row() {  
    Text(`UseStateVarByReference: ${params.paramA1} `)  
  }  
}  
@Entry  
@Component  
struct Parent {  
  @State label: string = 'Hello';  
  build() {  
    Column() {  
      // Pass the this.label reference to the overBuilder component when the overBuilder component is called in the Parent component.  
      overBuilder({ paramA1: this.label })  
      Button('Click me').onClick(() => {  
        // After Click me is clicked, the UI text changes from Hello to ArkUI.  
        this.label = 'ArkUI';  
      })  
    }  
  }  
}
分享
微博
QQ
微信
回复
2024-09-27 17:13:57
相关问题
HarmonyOS @builder方法ui刷新
28浏览 • 1回复 待解决
HarmonyOS @builder引用传递问题
34浏览 • 0回复 待解决
HarmonyOS @Builder UI刷新问题
23浏览 • 1回复 待解决
js 自定义组件如何传递方法
5902浏览 • 2回复 待解决
@Builder自定义构建函数,如何回参?
332浏览 • 1回复 待解决