美文网首页
vue 监听手机键盘状态(是否弹出)

vue 监听手机键盘状态(是否弹出)

作者: 小睿同学 | 来源:发表于2020-04-10 11:18 被阅读0次

1.data里定义 默认屏幕高度和实时屏幕高度

data(){
      return{
            defaultHeight: '0',  //默认屏幕高度
            nowHeight:  '0',  //实时屏幕高度
      }
}

2.获取 默认屏幕高度和实时屏幕高度

mounted: function() {
    //获取默认高度
    this.defaultHeight = $(window).height();
    window.onresize = () => {
        return (() => {
           //实时屏幕高度
           this.nowHeight =$(window).height();
        })();
    };
},

3.监听 键盘状态

watch: {
    nowHeight:function() {
        if(this.defaultHeight!= this.nowHeight){
         //键盘弹出操作
        }else{
         //键盘不弹出操作
        }
    }
}
就这样,End~

相关文章

网友评论

      本文标题:vue 监听手机键盘状态(是否弹出)

      本文链接:https://www.haomeiwen.com/subject/kmglmhtx.html