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

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

HarmonyOS
2024-12-20 16:15:29
浏览
收藏 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%')
  }
}
分享
微博
QQ
微信
回复
2024-12-20 18:35:30
相关问题
@ObjectLink @State同时使用
530浏览 • 1回复 待解决
HarmonyOS CustomDialog报错
971浏览 • 1回复 待解决
HarmonyOS @ObjectLink到底怎么
1039浏览 • 1回复 待解决
@BuilderParam修饰的属性报错
2614浏览 • 1回复 待解决
HarmonyOS " @State可以修饰ArrayList"
1300浏览 • 1回复 待解决
HarmonyOS CustomDialog自定义Dialog
1352浏览 • 1回复 待解决