HarmonyOS 用@CustomDialog修饰弹框之后使用@ObjectLink报错,能同时用@Component修饰吗

用@CustomDialog修饰弹框之后使用@ObjectLink报错,能同时用@Component修饰吗

HarmonyOS
2024-12-20 16:15:29
723浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

支持使用@Componet修饰@CustomDialog弹窗组件的,并且装饰器也可以正常工作,以下是在弹窗中使用@ObjectLink的样例代码:

@Observed
class Person {
  name: string = "Jerry"
  age: number = 0
}

@CustomDialog
@Component
struct CustomDialogExample {
  @ObjectLink curPerson: Person
  controller?: CustomDialogController
  build() {
    Column() {
      TextInput({text: this.curPerson.name})
        .onChange((input: string) => {
          this.curPerson.name = input
        })
        .width("100%")
        .height(100)
    }
    .width("100%")
    .backgroundColor(Color.White)
    .borderRadius({topLeft: 32, topRight: 32})
  }
}
@Entry
@Component
struct CustomDialogTest {
  @State person: Person = new Person()
  dialogController: CustomDialogController = new CustomDialogController({
    builder: CustomDialogExample({curPerson: this.person}),
    alignment: DialogAlignment.Bottom,
    customStyle: true
  })
  build() {
    RelativeContainer() {
      Text(this.person.name)
        .id('HelloWorld')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: 'container', align: VerticalAlign.Center },
          middle: { anchor: 'container', align: HorizontalAlign.Center }
        })
        .onClick(() => {
          this.dialogController.open()
        })
    }
    .height('100%')
    .width('100%')
  }
}
  • 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.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
分享
微博
QQ
微信
回复
2024-12-20 18:35:30


相关问题
@ObjectLink @State同时使用
276浏览 • 1回复 待解决
HarmonyOS CustomDialog报错
776浏览 • 1回复 待解决
HarmonyOS @ObjectLink到底怎么
794浏览 • 1回复 待解决
@BuilderParam修饰的属性报错
2480浏览 • 1回复 待解决
HarmonyOS " @State可以修饰ArrayList"
1133浏览 • 1回复 待解决
HarmonyOS CustomDialog自定义Dialog
1154浏览 • 1回复 待解决