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

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

阅读 598
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%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进