你想要的(Vue)移动端点击输入框,弹出键盘,底部被顶起问题


问题描述:

Vue开发中,当我们相对于父视图的底部布局子控件时,需要用position:fixed,如果页面内容不是很长,没有超出屏幕范围,那就还好,没有问题;一旦超出屏幕范围,当你点击输入框,弹出键盘时,底部固定定位的子控件就会被顶起来。
这个问题在iOS端不会出现,在安卓端会出现,原因是键盘加载方式不一样,这里不作详情解答。

开始

第一步: 先在 data 中去 定义 一个记录高度是 属性

data () {    
	return {        
		docmHeight: '0',  //默认屏幕高度       
		showHeight:  '0',   //实时屏幕高度        
		hidshow:true  //显示或者隐藏footer,      
		isResize:false //默认屏幕高度是否已获取   
	};  
},

第二步: 我们需要将 reisze 事件在 vue mounted 的时候 去挂载一下它的方法

mounted() {    // window.onresize监听页面高度的变化   
	 window.onresize = ()=>{        
		 return(()=>{                     
			 if (!this.isResize) {                               
				 // 默认屏幕高度                              
				 this.docmHeight = document.documentElement.clientHeight                                
				 this.isResize = true                       
			 }                        
				 // 实时屏幕高度                       
				 this.showHeight = document.body.clientHeight         
		 })()    
	 }  
 },

第三步:watch监控比较,判断按钮是否该显示出来

showHeight:function() {        
	if(this.docmHeight > this.showHeight){            
		this.hidshow=false        
	}else{            
		this.hidshow=true        
	}    
}

第四步:在模板中给footer添加v-show

	<div class="footer" v-show="hidshow">
	
	移动端点击输入框,弹出键盘,底部被顶起问题
	
	</div>
Logo

前往低代码交流专区

更多推荐