代码:
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
build() {
Column() {
Web({ src: 'file://' + getContext().cacheDir + '/toutiao/index.html',
controller: this.controller })
.width('100%')
.height('100%')
.domStorageAccess(true)
}
.width('100%')
.height('100%')
}
}
检查WebView的加载方式(如使用loadUrl还是loadFileUrl等),并确保传入的参数是有效的。