HarmonyOS 报错Cannot find name 'backgroundColor'. Did you mean the instance member 'this.backgroundColor'?

自定义的CardView想在调用的地方设置backgroundColor等属性值,无法设置报以上错误。

// 自定的CardView
@Component
export struct CardView {
  @BuilderParam private content: () => void // 控件占位符

  build() {
    Column() {
      this.content()
    }
    .shadow({
      radius: 6,
      color: Color.Grey,
      offsetX: 0,
      offsetY: 0
    })
    .padding({
      left: 30,
      right: 30,
      top: 20,
      bottom: 20
    })
    .borderRadius(6)
    .alignItems(HorizontalAlign.Start)
  }
}

// 调用CardView
CardView() {
  Row() {
  }.width("100%")
}
.backgroundColor(Color.White) // 这里报错:Cannot find name 'backgroundColor'. Did you mean the instance member 'this.backgroundColor'?
HarmonyOS
3天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa

参考示例如下:

@Entry
@Component
struct Page {
  @Builder
  test() {
    Text('this is test11')
  }

  build() {
    Stack() {
      CardView({
        content: this.test
      })
        .backgroundColor(Color.White)
    }
  }
}

@Component
struct CardView {
  @Builder
  blank() {
  }

  @BuilderParam content: () => void = this.blank

  build() {
    Column() {
      this.content()
    }.shadow({
      radius: 6,
      color: Color.Grey,
      offsetX: 0,
      offsetY: 0
    })
    .padding({
      left: 30,
      right: 30,
      top: 20,
      bottom: 20
    })
    .borderRadius(6)
    .alignItems(HorizontalAlign.Start)
  }
}
分享
微博
QQ
微信
回复
3天前
相关问题
HarmonyOS Cannot find name 'ESObject'
312浏览 • 0回复 待解决