HarmonyOS Web加载url报错?

有一个详情页面,上半部分是原生,下半部分是web加载的一个URL,时不时的总会报错:the WebviewController must be associated with a web component,使用了setTimeout延迟1s操作还是不行。

阅读 572
1 个回答

The WebviewController must be associated with a Web component错误是WebviewController没有和具体的Web组件关联,即Web组件和WebviewController还没有绑定。

1、WebviewController可以控制Web组件各种行为。一个WebviewController对象只能控制一个Web组件,且必须在Web组件和WebviewController绑定后,才能调用WebviewController上的方法(静态方法除外)。

参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-webview-V5\#webviewcontroller

2、onControllerAttached:当Controller成功绑定到Web组件时触发该回调,最早可以在onControllerAttached回调中使用WebviewController相关方法。

参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-web-V5\#oncontrollerattached10