欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 焦点 > 【在qiankun模式下el-dropdown点击,浏览器报Failed to execute ‘getComputedStyle‘ on ‘Window‘: parameter 1 is not o

【在qiankun模式下el-dropdown点击,浏览器报Failed to execute ‘getComputedStyle‘ on ‘Window‘: parameter 1 is not o

2025/5/16 19:15:25 来源:https://blog.csdn.net/qq_39750019/article/details/147980862  浏览:    关键词:【在qiankun模式下el-dropdown点击,浏览器报Failed to execute ‘getComputedStyle‘ on ‘Window‘: parameter 1 is not o

在qiankun模式下el-dropdown点击,浏览器报Failed to execute ‘getComputedStyle’ on ‘Window’: parameter 1 is not of type ‘Element’` 错误

在qiankun模式下el-dropdown点击,浏览器报Failed to execute ‘getComputedStyle’ on ‘Window’: parameter 1 is not of type ‘Element’` 错误

在qiankun 前端框架中,主应用开启了样式隔离,
跳转子应用后,el-dropdown-menu点击,浏览器报浏览器报Failed to execute ‘getComputedStyle’ on ‘Window’: parameter 1 is not of type ‘Element’` 错误。
在这里插入图片描述

问题描述

在qiankun 前端框架中,主应用开启了样式隔离,
跳转子应用后,el-dropdown-menu点击,浏览器报浏览器报Failed to execute ‘getComputedStyle’ on ‘Window’: parameter 1 is not of type ‘Element’` 错误:

  1. 主应用 ,开启了qiankuan沙箱机制,乾坤会对子应用的DOM和样式进行隔离,可能回导致el-dropdown-menu的定位和样式定位的计算;
start({sandbox: {experimentalStyleIsolation: true,strictStyleIsolation: true},prefetch: 'all'
})
  1. getComputedStyle 报错,el-dropdown-menu 在计算样式时,可能无法正确获取 DOM 元素,导致 TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element' 错误;

  2. 查看单独子应用的DOM元素
    在这里插入图片描述

  3. 查看qiankun模式下的子应用的DOM元素
    没有自动的定位和样式定位的计算在这里插入图片描述

解决方法

在子应用的main.js里面增加方法

// 独立运行时
if (!window.__POWERED_BY_QIANKUN__) {render();
}else{const style = document.createElement('style');style.textContent = `svg { display: inline-block; overflow: visible!important; }use { width: 100%!important; height: 100%!important; }`;document.head.appendChild(style);const rawGetComputedStyle = window.getComputedStyle;window.getComputedStyle = function (element) {try {return rawGetComputedStyle.call(window, element);} catch (e) {console.warn('getComputedStyle error:', e);return {getPropertyValue: () => '',};}}
}

重启一下子应用,完美解决

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词