uniapp 애플리케이션은 메시지를 직접 전달합니다. (uniapp은 다른 uniapp 애플리케이션 간의 통신을 위해 h5에 패키징되어 있습니다.)
구현은 다음과 같습니다.
1. https://gitee.com/dcloud/uni-app/raw/master/dist/uni.webview.1.5.2.js를 방문하여 다음과 같이 코드를 로컬 h5 프로젝트에 복사합니다. 그림:
2. uniapp h5 프로젝트의 Main.js에 도입되었습니다.
import * as uni from './common/uni_webview.js'
document.addEventListener("UniAppJSBridgeReady", function() {
console.log("ewee")
Vue.prototype.myUni = uni
});
var foo = 'bar';
3. uniapp h5 프로젝트는 다음과 같이 다른 프로젝트에 메시지를 보냅니다.
this.myUni.webView.postMessage({
data: {
action: "xxxxxxxx",
},
});
4. 다른 프로젝트에서는 다음과 같은 메시지를 받습니다.
(1) 웹뷰 통합(기본 사용법: https://uniapp.dcloud.io/comComponent/web-view)
<web-view ref="webview" src="http:/xxxx" **@message**="handleMessage">
</web-view>
(2)메시지 수신
methods: {
handleMessage: function(data) {
console.log("data", data)
},
}