解决ERROR ResizeObserver loop completed with undelivered notifications.
该报错虽然不影响项目运行,但是影响开发效率,总是弹出报错的黑框很烦人
该报错原因: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);
}
}