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