预览出现问题:Preview failed. View details in the PreviewerLog window

预览出现问题:Preview failed. View details in the PreviewerLog window

HarmonyOS
2024-07-31 10:24:45
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
易安安安

鉴于页面或组件在包含`@Consume`(或`@Link`)装饰的成员时,预览过程中可能遭遇白屏问题,特此建议开发者避免直接预览含有此类装饰成员的子组件。为获取子组件的预览效果,请通过预览其父组件的方式来进行,以确保预览过程的稳定性和准确性。

// 建议通过在ParentComp上添加@Preview,预览ParentComp来查看ChildComp的预览效果
@Preview //组件预览
@Component
struct ParentComp {
装饰的变量reviewVotes由入口组件ParentComp提供其后代组件
  @Provide reviewVotes: number = 10;

  build() {
    Column() {
      Button(`reviewVotes(${this.reviewVotes}), give +1`)
        .onClick(() => this.reviewVotes += 1)
      ChildComp()
    }
  }
}

// @Preview 不建议直接预览ChildComp
@Component
struct ChildComp {
装饰的变量通过相同的属性名绑定其祖先组件ParentComp内的@Provide装饰的变量
  @Consume reviewVotes: number;
  build() {
    Column() {
      Text(`reviewVotes(${this.reviewVotes})`)
      Button(`reviewVotes(${this.reviewVotes}), give +1`)
        .onClick(() => this.reviewVotes += 1)
    }
    .width('50%')
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-07-31 18:07:09
相关问题
HarmonyOS 编译curl出现问题
1634浏览 • 1回复 待解决
ERROR: Schema validate failed.
1578浏览 • 1回复 待解决
【bearpi】hb build -f出现问题
1363浏览 • 0回复 待解决
Error: Install eTS 3.1.0.0 failed.
4673浏览 • 1回复 待解决
js采集声音出现问题怎么处理?
4010浏览 • 1回复 待解决
编译出现问题,请问怎么解决?
1136浏览 • 1回复 待解决
ArkUI sdk9使用worker出现问题
4852浏览 • 1回复 待解决
Hi3861 SDK编译出现问题
12912浏览 • 3回复 待解决
h3861编译出现问题197行
7064浏览 • 1回复 待解决
hispar开发套件环境配置编译出现问题
3183浏览 • 0回复 待解决
hi3861开发板nfc例程出现问题
9846浏览 • 2回复 待解决
升级api11出现问题,该怎么解决啊?
2034浏览 • 1回复 待解决