根据屏幕的高度进行判断键盘是否弹起
data{
retrun{
defaultPhoneHeight: "", //屏幕默认高度
nowPhoneHeight: "", //屏幕现在的高度
}
},
mounted() {
this.defaultPhoneHeight = window.innerHeight;
window.onresize = () => {
this.nowPhoneHeight = window.innerHeight;
};
},
destroyed() {
window.onresize = null;
},
watch: {
nowPhoneHeight: function() {
if (this.defaultPhoneHeight > this.nowPhoneHeight) {
console.log('键盘弹出事件')
} else {
console.log('键盘收起事件')
}
},