vue移动端,解决手机上底部样式被软键盘顶起
data(){
return{
screenHeight: document.body.clientHeight, // 默认值
originHeight: document.body.clientHeight, // 默认高度 在watch比较
height:true
}
},
mounted(){
//解决键盘弹出底部顶起
let that= this
window.onresize = () => {
return (() => {
that.screenHeight= document.body.clientHeight
})()
}
},
watch: {
screenHeight (val) {
if(this.originHeight-val > 50) {
// 键盘显示
this.height = false
}else{
// 键盘收起
this.height = true
}
}
},
beforeDestroy () {
window.onresize = null; //注销window.onresize事件
}