问题定位如下:.onControllerAttached(() => { this.controller.setCustomUserAgent(this.controller.getUserAgent() + 'whatyApp whatyApiApp HarmonyOSNEXT');(放在这不行) }) .onPageBegin(() => { this.controller.setCustomUserAgent(this.controller.getUserAgent() + 'whatyApp whatyApiApp HarmonyOSNEXT');(放在这行) // 加载hmOS.js this.controller.runJavaScript(globalThis.hmApiJS) })设置UA 是会影响页面加载的。文档推荐放在onControllerAttached 是因为 放在onPageBegin中会发生二次加载。而vue的router属于前端路由,它的路由方式和HarmonyOS的router是不同的,是通过hash的方式实现路由。在onPageBegin触发了二次加载让功能实现,属于特殊场景。如果是非单页面应用,且不采用前端路由的方式,推荐放在onControllerAttached中。
问题定位如下:
设置UA 是会影响页面加载的。文档推荐放在onControllerAttached 是因为 放在onPageBegin中会发生二次加载。而vue的router属于前端路由,它的路由方式和HarmonyOS的router是不同的,是通过hash的方式实现路由。在onPageBegin触发了二次加载让功能实现,属于特殊场景。如果是非单页面应用,且不采用前端路由的方式,推荐放在onControllerAttached中。