首页 > 其他分享 >解决ERROR ResizeObserver loop completed with undelivered notifications.

解决ERROR ResizeObserver loop completed with undelivered notifications.

时间:2024-10-09 11:00:28浏览次数:7  
标签:vue const callback completed timer undelivered notifications window ResizeObserv

https://www.cnblogs.com/luo9tian/p/18116299

该报错虽然不影响项目运行,但是影响开发效率,总是弹出报错的黑框很烦人

该报错原因:new ResizeObserver包裹的方法,在布局发生变化时,不支持每帧都调用

解决方法:用 window.requestAnimationFrame包裹回调函数

App.vue/main.js中加入以下这段代码即可解决:

// app.vue写在script里面  main.js写在app挂载完之后
const debounce = (fn, delay) => {
  let timer
   return (...args) => {
     if (timer) {
       clearTimeout(timer)
     }
     timer = setTimeout(() => {
       fn(...args)
     }, delay)
   }
}
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver{
   constructor(callback) {
     callback = debounce(callback, 200);
     super(callback);
   }
}

标签:vue,const,callback,completed,timer,undelivered,notifications,window,ResizeObserv
From: https://www.cnblogs.com/xjzyy/p/18453794

相关文章