需求:这边是uniapp开发的APP  需要内嵌H5(vue),就得使用web-view跳转网页

H5端

 在vue的index,html文件引入web-view的插件
<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.1.js"></script>

在vue界面当中
        // 通过事件使用uniapp的 方法
        postMsg(){
            // 重点 “uni.postMessage,像APP端发送消息”
            uni.postMessage({
                data: {
                action: '我是消息'
                }
            });
        },

uniapp端

<template>
<view :style="'paddingTop:' + statusBarHeight + 'px;backgroundColor:' + warpperBgColor">
<web-view ref="webview" @message="getMessage" @onPostMessage="getPostMessage" :src="url" :style="'height: ' + windowHeight + 'px;'" />
</view>
</template>

设置内容宽高
methods: {
 设置内容宽高

nitializeUrl() {
            let info = uni.getSystemInfoSync();
            this.windowHeight = info.windowHeight - info.statusBarHeight;
            this.statusBarHeight = info.statusBarHeight;
        },
 
  H5与APP通信    这里接收H5传递的参数,触发事件

        getMessage(e) {
            const val = e.detail.data[0].action || ''
            if(val) {
                uni.reLaunch({
                    url:'/pages/home'
                })
            }
           
        },
}

 
 

  

最新文章

  1. JMX
  2. 《利用Python进行数据分析》第5章学习笔记
  3. Ruby 类案例
  4. YbRapidSolution.Mvc判断不同用户登录不同页面
  5. p3p之讲解
  6. Linux系统编程(21)——信号的产生
  7. c++ primer plus 习题答案(3)
  8. tag标签记录
  9. linux bash 和 sh的区别
  10. 51NOD 1185 威佐夫游戏 V2(威佐夫博弈)
  11. UICollectionViewController的用法1
  12. vps 切换内核
  13. 用Copy命令合并文件
  14. [STL][C++]VECTOR
  15. PAT 1053 住房空置率 (20)(代码+思路)
  16. 漫谈js自定义事件、DOM/伪DOM自定义事件
  17. Android倒计时案例展示
  18. VUE中关于表单提交的简单实现
  19. main(argc,argv[])
  20. 【python】Python的logging模块封装

热门文章

  1. jquerylib表单
  2. 多线程爬取wallhaven
  3. Redis学习整理
  4. vivo 实时计算平台建设实践
  5. LeetCode HOT 100:验证二叉搜索树(从左右子树获取信息进行推导)
  6. Redis缓存何以一枝独秀?(2) —— 聊聊Redis的数据过期、数据淘汰以及数据持久化的实现机制
  7. (8)go-micro微服务Mysql配置
  8. 算法之倍增和LCA:论点与点之间的攀亲戚
  9. post方法易错地方
  10. 动力节点——day03