vue監聽瀏覽器高度


<div id="TableConConStucke" :style="contentStyleObj">
    省去內容......
</div>

data中:
contentStyleObj: { height: "", overflow: "auto" } 
methods中:
 getHeight() {
      // 獲取瀏覽器高度  768 1080一般筆記本瀏覽器高度
      if (window.innerHeight < 768 || window.innerHeight < 1080) {
        this.contentStyleObj.height = "361px";
      } else {
        this.contentStyleObj.height = "auto";
      }
    },

created中
// 監聽瀏覽器高度事件
    window.addEventListener("resize", this.getHeight);
    // 執行瀏覽器高度事件
    this.getHeight();

destroyed中
// 頁面一關閉,銷毀監聽事件
    window.removeEventListener("resize", this.getHeight);


免責聲明!

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



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