鸿蒙Arkts (api 12 )Error message:@Component ‘@Component ‘PermissionDialog‘[130]‘:

记录一下今天犯的一个错误@State 装饰器的属性值不能是函数类型(function),因此在定义对话框时无法将事件处理函数直接赋值给这些属性。 

报错误如下:
Error message:@Component '@Component 'PermissionDialog'[130]': Illegal variable value error with decorated variable undefined 'onPositiveClick': failed validation: 'undefined, null, number, boolean, string, or Object but not function, not V3 @observed / @track class, attempt to assign value type: 'function', value: 'undefined'!

@CustomDialog
 export default  struct PermissionDialog{
  @State titleText:string='标题';
  @State contentText:string='内容';
  @State positiveText:string='确定';
  @State negativeText:string='取消';

  // @State  onPositiveClick: () => void = () => {};
  // @State onNegativeClick: () => void = () => {}; 修改前

  private  onPositiveClick: () => void = () => {};
  private onNegativeClick: () => void = () => {}; 修改后

  controller: CustomDialogController
  build() {
    Column(){
      Text(this.titleText).margin({top:10})
      Text(this.contentText).margin({top:20,bottom:10})
      Text(this.positiveText).margin({top:20,bottom:10}).onClick(()=>this.onPositiveClick())
      Text(this.negativeText).margin({top:20,bottom:10}).onClick(()=>this.onNegativeClick())

    }.justifyContent(FlexAlign.Start).padding({left:20,right:20})

  }
}


 

                

相关推荐

  1. LeetCode 150, 112, 130

    2024-07-22 18:56:03       17 阅读
  2. 面试经典150题(10-13)

    2024-07-22 18:56:03       51 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-22 18:56:03       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-22 18:56:03       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-22 18:56:03       45 阅读
  4. Python语言-面向对象

    2024-07-22 18:56:03       55 阅读

热门阅读

  1. 交换机(Switches)和桥(Bridges)的区别

    2024-07-22 18:56:03       15 阅读
  2. 测试面试宝典(二十一)—— get和post的区别

    2024-07-22 18:56:03       13 阅读
  3. ESP8266AT指令查看有哪些指令可用(3)

    2024-07-22 18:56:03       12 阅读
  4. Oracle(15)什么是索引(Index)?

    2024-07-22 18:56:03       13 阅读
  5. CSS 的@media规则,响应式的一种解决方案

    2024-07-22 18:56:03       12 阅读