美文网首页
VUE中监听窗口宽高

VUE中监听窗口宽高

作者: 小碗吃不了 | 来源:发表于2020-06-12 13:28 被阅读0次
  • 在data中设置

    data() {
      return {
        screenHeight: document.documentElement.clientHeight, //屏幕高度
        screenWidth: document.documentElement.clientWidth, //屏幕宽度
      }
    }
    
  • 在mounted中设置(在resize中设置即可)

    mounted() {
      let that = this;
      window.addEventListener("resize", function() {
        that.screenHeight = document.body.clientHeight;
        that.screenWidth = document.body.clientWidth;
        console.log(that.screenHeight);
      });
    },

相关文章

网友评论

      本文标题:VUE中监听窗口宽高

      本文链接:https://www.haomeiwen.com/subject/tumgtktx.html