diff --git a/zh-cn/application-dev/reference/apis-arkweb/arkts-apis-webview-WebviewController.md b/zh-cn/application-dev/reference/apis-arkweb/arkts-apis-webview-WebviewController.md index 779d3b2c4ae0c544cbf0ef8e4383113cb3cd074b..e3d498d988bee89963b1874a9bd10bd8c3d87b6f 100644 --- a/zh-cn/application-dev/reference/apis-arkweb/arkts-apis-webview-WebviewController.md +++ b/zh-cn/application-dev/reference/apis-arkweb/arkts-apis-webview-WebviewController.md @@ -500,7 +500,40 @@ struct WebComponent { } ``` -加载本地资源 +指定baseURL。 +```ts +// xxx.ets +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('loadData') + .onClick(() => { + try { + this.controller.loadData( + "", // 会尝试从"https://xxx.com/" + "aa/bb.jpg"加载该图片 + "text/html", + "UTF-8", + "https://xxx.com/", + "about:blank" + ); + } catch (error) { + console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} +``` + +加载本地资源。 ```ts // xxx.ets import { webview } from '@kit.ArkWeb';