HarmonyOS 连续两次@Link之后UI没更新

PageA里面@State变量loginAgreement传到ComponentB里面@Link修饰的loginAgreement上ComponentB里面引用组件C里面@Link修饰的loginAgreement。页面切换状态时候组件C中checkBox没有被选中,打印值是true。

HarmonyOS
2024-12-27 15:09:06
7779浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

双向绑定的时候需要使用$进行值绑定操作从而驱动页面刷新。

import { ComponentB } from './ComponentB'
@Entry
@Component
export struct PageA{
  @State loginAgreement: boolean = true
  build() {
    Column() {
      ComponentB({
        // loginAccount: this.loginAccount,
        loginAgreementShow: true,
        loginAgreement: $loginAgreement
      })
    }}
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
import { ComponentC } from './ComponentC'
@Component
export struct ComponentB{
  @State loginAgreementShow: boolean = true
  @Link loginAgreement: boolean
  build() {
    ComponentC({
      selected:$loginAgreement
    })
  }
}
@Component
export struct ComponentC{
  @State loginAgreementShow: boolean = true
  @Link selected : boolean
  build() {
    Column() {
      Checkbox() {
        Text('sssssssssssssssssssssssssss').fontColor(Color.Red).fontSize(16).width('auto')
      }
      .onChange((value) => {
        this.selected = value
      })
      .select(this.selected )
    }}
}
  • 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.

另外Checkbox的select是从API version 10开始,该属性支持$$双向绑定变量的。

分享
微博
QQ
微信
回复
2024-12-27 17:21:06


相关问题
UI刷新
1657浏览 • 1回复 待解决
HarmonyOS Native怎么更新UI?
733浏览 • 1回复 待解决