vue onresize 不起作用

// window.onresize = ()=>{ // 定义窗口大小变更通知事件
    //   screenObj.width = document.documentElement.clientWidth; //窗口宽度
    //   screenObj.height = document.documentElement.clientHeight; //窗口高度
    //   console.log(screenObj)
    //   this.$store.dispatch("app/setScreen",screenObj);
    // };

  

vue 监听窗口改变 , 这么写不起作用 , 而是

要用

addEventListener
 
window.addEventListener("resize",()=>{
        screenObj.width = document.documentElement.clientWidth; //窗口宽度
      screenObj.height = document.documentElement.clientHeight; //窗口高度
      console.log(screenObj)
      this.$store.dispatch("app/setScreen",screenObj);
      })

 真的好奇怪 , 到现在我也没明白是为什么 , 挂载的时候不起作用 , 需要刷新才能用 ,比如router的跳转, 注意不是浏览器的刷新

原文地址:https://www.cnblogs.com/sunjinggege/p/14832324.html