uniapp小程序中使用web-view中的坑(cover-view安卓手机无法触发touch事件)巧妙解决

背景:uniapp开发的小程序中使用web-view引入H5页面,这个H5也是uniapp开发 需求:(1)增加一个解读报告按钮,仅可以上下拖拽(2)点击后携带参数跳转到小程序页面

错误实践:

首先想到的是使用cover-view来写这个解读报告按钮,有两种局限性:

cover-view覆盖在原生组件上的文本视图

1、安卓手机touch事件没触发(目前没找到解决方案) 2、cover-view中不能包含其他元素,所以uniapp中的movable-areamovable-view用不了

解决方案:

1、在uniapp的h5中写拖拽,使用movable-areamovable-view,代码如下: 2、uniapp中点击按钮跳转到小程序 index.html中加入如下代码:放到body下面

复制代码
	<script type="text/javascript" src="./static/uni-webview-js.js"></script>
	<script type="text/javascript" type="text/javascript">
	     // 待触发 `UniAppJSBridgeReady` 事件后,即可调用 uni 的 API。注意uni sdk放到body下面
	        document.addEventListener('UniAppJSBridgeReady', function() {
	            uni.webView.getEnv(function(res) {
	                console.log('当前环境:' + JSON.stringify(res));
	            });
	        });
	</script>
xml 复制代码
<movable-area v-if="pdfSrc">
    <movable-view direction="all" damping="50" friction="0.5" scale="1.5" animation="ease" @click="freeInterpretation">
		<view class="dragOuter">
			<view>解读</view>
			<view>报告</view>
		</view>
    </movable-view>
</movable-area>
javascript 复制代码
freeInterpretation(){
	uni.webView.navigateTo({
            url: '/packageD/advanceReport/advanceReport?res_id='+this.options.res_id
	});
},

还有一种想法,给cover-view外层的view标签添加touch事件,还没去尝试

相关推荐
橙序员小站1 小时前
Agent Skill 是什么?一文讲透 Agent Skill 的设计与实现
前端·后端
炫饭第一名4 小时前
速通Canvas指北🦮——基础入门篇
前端·javascript·程序员
王晓枫4 小时前
flutter接入三方库运行报错:Error running pod install
前端·flutter
符方昊4 小时前
React 19 对比 React 16 新特性解析
前端·react.js
ssshooter4 小时前
又被 Safari 差异坑了:textContent 拿到的值居然没换行?
前端
曲折5 小时前
Cesium-气象要素PNG色斑图叠加
前端·cesium
Forever7_5 小时前
Electron 淘汰!新的桌面端框架 更强大、更轻量化
前端·vue.js
Angelial5 小时前
Vue3 嵌套路由 KeepAlive:动态缓存与反向配置方案
前端·vue.js
jiayu5 小时前
Angular学习笔记24:Angular 响应式表单 FormArray 与 FormGroup 相互嵌套
前端
jiayu5 小时前
Angular6学习笔记13:HTTP(3)
前端