使用Element-plus,页面重置大小时,出现如下报错:
Uncaught runtime errors: × ERROR ResizeObserver loop limit exceeded at handleError (webpack-internal:///./node_modules/webpack-dev-server/client/overlay.js:252:58) at eval (webpack-internal:///./node_modules/webpack-dev-server/client/overlay.js:271:7)
错误是由 webpack引起的,出现在webpack-dev-server的overlay.js文件中。
这个错误通常是由于观察元素的大小变化导致的循环问题。要解决这个问题,很简单。
把下面代码粘在app.vue
或者main.js中都可以
const debounce = (fn, delay) => {
let timer = null;
return function () {
let context = this;
let args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
fn.apply(context, args);
}, delay);
}
}
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver{
constructor(callback) {
callback = debounce(callback, 16);
super(callback);
}
}
搞定!!!