HarmonyOS wrapBuilder.builder属性方法,参数修改后UI未更新?

因项目原因,使用第三方模块的子组件时,使用了wrapBuilder。但在使用过程中,发现wrapBuilder.builder()的参数修改后,第三方模块的子组件ui未更新。请问这种清空下,如何能实现wrapBuilder.builder()的参数后,第三方模块的子组件ui能同步发生更新呢?

阅读 556
1 个回答

解决方式

class a{
  stockCode:string=''
}
@Component
struct StockCodeBuilder{
  @Prop stockCode: string;
  build() {
    Row() {
      Text('股票代码传递给wrapBuilder:'+this.stockCode)
    }
  }
}

@Builder
function myBuilder($$:a){
  StockCodeBuilder({
    stockCode: $$.stockCode
  })
}

let globalBuilder: WrappedBuilder<[a]> = wrapBuilder(myBuilder);

@Entry()
@Component
export struct WrapBuilderDemo {
  @State stockCode: string = '000001';

  build() {
    Column(){
      Button('切换股票代码').onClick(() => {
        this.stockCode = this.stockCode === '000001' ? '000002' : '000001';
      })
      Text('切换后的股票代码:' + this.stockCode)

      Divider().strokeWidth('0.5').width('100%').margin({top: 10, bottom: 10})
      globalBuilder.builder({ stockCode:this.stockCode })
    }
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进