最近做微信公眾號活動,需要首頁往input中輸入內容,點擊input軟鍵盤tabbar被頂起來,網上借鑒很多(踩了許多坑)最后自己實踐出來。
<--!將手機屏幕的默認高度和實時高度獲取--> data(){ docmHeight: document.documentElement.clientHeight, //默認屏幕高度 showHeight: document.documentElement.clientHeight, //實時屏幕高度 hidshow: true, //顯示或者隱藏footer, } <!--把window.onresize事件掛在到mounted函數上--> mounted(){ window.onresize = () => { return (() => { window.fullHeight = document.documentElement.clientHeight; that.showHeight = window.fullHeight; })() }; } <!--在watch中監聽實時高度--> watch: { showHeight (val) { let that = this; that.show2 = true; if (that.docmHeight > val){ that.hidshow = false; } else{ that.hidshow = true; } } },
實時對比屏幕高度來顯示隱藏tabbar