当前位置: 代码迷 >> 综合 >> vue使用函数防抖监听窗口的变化
  详细解决方案

vue使用函数防抖监听窗口的变化

热度:96   发布时间:2023-10-10 19:19:42.0
    resizeHandler: function() {if (this.timer) clearTimeout(this.timer);this.timer = setTimeout(() => {this.setWid();this.isShow();}, 500);},

添加监听事件

mounted() {window.onresize = () => {this.resizeHandler();};
}

移除监听事件

  beforeDestroy() {window.onresize = null;}

 

  相关解决方案