解決ERROR ResizeObserver loop completed with undelivered notifications.

眈眈逐逐發表於2024-10-09

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

相關文章