HarmonyOS webVIew加载不兼容,页面无法打开?

webview加载不兼容,页面无法打开。

错误日志:

Uncaught TypeError: Cannot read properties of null (reading 'getItem') at getAppType (invoicing.ts:27:29) at invoicing.ts:40:14
阅读 585
1 个回答

1、当访问在线网页时,需要在module.json5文件中添加网络权限:ohos.permission.INTERNET。

2、需要加上.domStorageAccess(true)属性,保证资源可以正常加载并显示。

文档请参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/cta-build-web-applications-using-web-components-V5\#section875973412449

示例如下:

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

@Entry
@Component
struct WebComponent {
  controller: webview.WebviewController = new webview.WebviewController()
  build() {
    Column() {
      Web({ src: 'xxx', controller: this.controller })
        .domStorageAccess(true)
        .fileAccess(true)
    }
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进