vue中實時監聽移動端屏幕高度(采坑后實踐)


最近做微信公眾號活動,需要首頁往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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM