
在 vue 项目中,当在微信端输入信息后,键盘会弹出导致页面被压缩。这个问题可以通过在 login.vue 中使用 fixscroll 方法来解决,该方法将窗口滚动到 (0, 0) 位置。
然而,如果此方法不起作用,还有其他解决方案:
1. reposition 固定元素
立即学习“前端免费学习笔记(深入)”;
如果页面压缩是因为 position:fixed 或 position:sticky 元素被键盘顶了上来,可以根据窗口高度触发是否显示这些元素:
mounted() {
window.addeventlistener('resize', () => {
const threshold = window.innerheight + 经验值;
if (window.innerheight < threshold) {
this.$refs.buttonwrap.style.display = "none";
} else {
this.$refs.buttonwrap.style.display = "block";
}
})
}2. 使用第三方库
可以考虑使用第三方库,如 vue-vclick-outside 或 vue-click-outside-mobile,以便在键盘弹起时触发功能。
3. 使用 css 媒体查询
可以使用 css 媒体查询根据屏幕高度调整样式:
@media (max-height: xxxpx) {
.fixed-container {
display: none !important;
}
}以上方法都可以解决键盘弹起时导致页面压缩的问题。请注意,具体解决方案取决于页面布局和项目需求。











