- //创建子页面并添加到当前页面
- var wv = plus.webview.create("/hybrid/html/index.html")
- var currentWebview = this.$scope.$getAppWebview();
- currentWebview.append(wv);
- //重点: 监听子页面uni.postMessage返回的值
- plus.globalEvent.addEventListener('plusMessage', function(msg){
- if(msg.data.args.data.name == 'postMessage'){
- console.log('子页面返回的数据为:'+JSON.stringify(msg.data.args.data.arg));
- }
- });
- <script src="uni.webview.1.5.2.js"></script>
- <script>
- document.addEventListener('UniAppJSBridgeReady', function() {
- //子页面发送数据
- uni.postMessage({
- data: {
- action: 'message'
- }
- });
- })
- </script>