预览出现问题: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%')
  }
}
分享
微博
QQ
微信
回复
2024-07-31 18:07:09
相关问题
HarmonyOS 编译curl出现问题
174浏览 • 1回复 待解决
【bearpi】hb build -f出现问题
648浏览 • 0回复 待解决
编译出现问题,请问怎么解决?
181浏览 • 1回复 待解决
js采集声音出现问题怎么处理?
3131浏览 • 1回复 待解决
ERROR: Schema validate failed.
230浏览 • 1回复 待解决
Hi3861 SDK编译出现问题
11863浏览 • 3回复 待解决
ArkUI sdk9使用worker出现问题
3574浏览 • 1回复 待解决
h3861编译出现问题197行
6092浏览 • 1回复 待解决
Error: Install eTS 3.1.0.0 failed.
3565浏览 • 1回复 待解决
hispar开发套件环境配置编译出现问题
2011浏览 • 0回复 待解决
hi3861开发板nfc例程出现问题
8533浏览 • 2回复 待解决
升级api11出现问题,该怎么解决啊?
745浏览 • 1回复 待解决