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);

猜你喜欢

转载自www.cnblogs.com/home-/p/12195808.html