The uniapp application directly delivers messages (uniapp is packaged into h5 for communication between another uniapp application)
The implementation is as follows
1. Visit https://gitee.com/dcloud/uni-app/raw/master/dist/uni.webview.1.5.2.js and copy the code to the local h5 project, as shown in the figure:
2. In Main.js in the uniapp h5 project is introduced
import * as uni from './common/uni_webview.js'
document.addEventListener("UniAppJSBridgeReady", function() {
console.log("ewee")
Vue.prototype.myUni = uni
});
var foo = 'bar';
3. The uniapp h5 project sends a message to another project, implemented as follows
this.myUni.webView.postMessage({
data: {
action: "xxxxxxxx",
},
});
4. Another project receives messages as follows:
(1) Integrate web-view (basic usage: https://uniapp.dcloud.io/component/web-view)
<web-view ref="webview" src="http:/xxxx" **@message**="handleMessage">
</web-view>
(2)Receive messages
methods: {
handleMessage: function(data) {
console.log("data", data)
},
}