webview postMessage 和 history api 不兼容
发布于 5 年前 作者 yong42 5409 次浏览 来自 问答

web-view 里面的网页通过 history.pushState 跳转到新路由后,使用 postMessage,小程序 onMessage 获取不到最新的数据。

只有当 web-view 的 src 和 网页内部的src一致时,postMessage 才有效。

例如:

  1. 这是有效的

<web-view src=“http://127.0.0.1:8000” bindmessage=“onMessage”/>

网页:location.href => http://127.0.0.1:8000

  1. 这是无效的

<web-view src=“http://127.0.0.1:8000” bindmessage=“onMessage”/>

网页:location.href => http://127.0.0.1:8000/topics

1 回复

找到方法了,需要先调用

wx.ready

小程序的文档根本没写明。不如说都在小程序了,有安全域名还要签名干嘛啊。

回到顶部