HarmonyOS Watch没有回调

@ObjectLink @Watch('onCountUpdated') itemBean:WordList
  • 1.

itemBean中的属性发生改变时候,没有回调onCountUpdated方法

onCountUpdated(propName: string){
  console.warn('---','propName'+propName)
}
  • 1.
  • 2.
  • 3.
HarmonyOS
2024-12-25 12:00:35
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

可以监听到改变的:

@Observed
class ClassA {
  public c: number = 0;

  constructor(c: number) {
    this.c = c;
  }
}

@Component
struct ObjectLinkChild {
  @ObjectLink @Watch('onCountUpdated') testNum: ClassA;
  onCountUpdated(propName: string) {
    console.warn('---','propName'+propName)
  }

  build() {
    Text(`ObjectLinkChild testNum ${this.testNum.c}`)
      .onClick(() => {
        // 可以对ObjectLink装饰对象的属性赋值
        this.testNum.c = 47;
      })
  }
}

@Entry
@Component
struct Parent {
  @State testNum: ClassA[] = [new ClassA(1)];

  build() {
    Column() {
      Text(`Parent testNum ${this.testNum[0].c}`)
        .onClick(() => {
          this.testNum[0].c += 1;
        })

      ObjectLinkChild({ testNum: this.testNum[0] })
    }
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
分享
微博
QQ
微信
回复
2024-12-25 14:49:19
相关问题
HarmonyOS @Watch方法没有改变
639浏览 • 1回复 待解决
@Watch装饰器的执行顺序
966浏览 • 1回复 待解决
支付成功后没有收到
2661浏览 • 1回复 待解决
HarmonyOS 登录组件点击隐私没有
675浏览 • 1回复 待解决
使用华为支付,没有支付成功的
1381浏览 • 1回复 待解决
HarmonyOS 系统video没有加载中的
834浏览 • 1回复 待解决
HarmonyOS 事件
1036浏览 • 1回复 待解决