HarmonyOS web组件加载网页后,网页中的图片不能显示?

如题:HarmonyOS web组件加载网页后,网页中的图片不能显示?

阅读 606
1 个回答

Web组件加载部分网页中使用了文档对象模型存储接口(DOM Storage API),默认未开启导致网页加载出错。

需要设置Web组件domStorageAccess属性为true开启权限。

参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-web-V5\#domstorageaccess

参考代码:

import { webview } from '@kit.ArkWeb';

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';
  @State url: string = "xxx"
  private controller: webview.WebviewController = new webview.WebviewController();

  build() {
    RelativeContainer() {
      Web({
        src: this.url,
        controller: this.controller,
      })
        .domStorageAccess(true)
    }
    .height('100%')
    .width('100%')
  }
}