• 解决uni-app中使用webview键盘弹起遮挡input输入框问题


    这个平平无奇的回答,可能是全网最靠谱的解决方案。
    这里我用的是vue3 setup .vue文件的方式

    <view>
    <web-view :fullscreen="false" :webview-styles="{
           top: statusBarHeight+40,
     height:height,
     progress: {
    		color: 'green',
    		height:'1px' } }"   :src="url">web-view>
    view>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    解决这个问题的核心就在这个height,你不信把这个height去掉问题就解决了,可是会导致底部被遮挡住的问题。解决办法就是键盘弹起的时候把height改成null,放下的时候恢复。

    上魔法

    import {
    		onLoad,
    		onShow,
    		onReady,
    		onUnload,
    		onNavigationBarButtonTap,
    	} from "@dcloudio/uni-app";
    	const width = ref();
    	const height = ref();
    	const title = ref("标题");
    	const ref_webview = ref();
    	const statusBarHeight = ref(40)
    	onLoad((options) => {
    		url.value = options.url;
    		let res = uni.getSystemInfoSync();
    		width.value = res.screenWidth;
    		statusBarHeight.value = res.statusBarHeight;
    		height.value = res.screenHeight - statusBarHeight.value - 40;
    		
    		 uni.onKeyboardHeightChange(onKeyboardHeightChange);
    	});
    	onUnload(()=>{
    		 uni.offKeyboardHeightChange(onKeyboardHeightChange);
    	}) 
    	//这里是核心
    	function onKeyboardHeightChange(res){
    		if(res.height==0){
    			let res = uni.getSystemInfoSync();
    			height.value = res.screenHeight - statusBarHeight.value - 40;
    		}else{
    			height.value = null
    		}
    	}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    可以到这里下载体验我的app https://aweb123.com

    在这里插入图片描述

  • 相关阅读:
    Java架构师分布式搜索数据迁移
    springboot+quartz报错:Table ‘XXXX.QRTZ_TRIGGERS‘ doesn‘t exist
    linux 的文件权限案列
    6.14作业
    秸秆焚烧监控系统
    格式工厂安装与使用教程
    QT动态加载qss和rcc方式
    常用web协议学习与抓包实战
    导数的定义和介绍习题
    MongoDB基本操作增删改查
  • 原文地址:https://blog.csdn.net/weixin_35958891/article/details/136455609