当前位置: 首页 > news >正文

【在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: () => '',};}}
}

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

相关文章:

  • 矫平机深度解析:技术细节、行业应用与未来革新
  • set, multiset ,unordered_set; map, multimap, unordered_map
  • 本地部署Firecrawl+Dify调用踩坑记录
  • MySQL 8.0 OCP 1Z0-908 101-110题
  • C++delete详解剖析
  • 【测试】测试分类
  • 5月15日星期四今日早报简报微语报早读
  • 视频分辨率增强与自动补帧
  • 【.net core】.net core 6.0添加WCF服务引用
  • 沐渥氮气柜氧含量控制核心目标
  • RHCA笔记
  • pgsql14自动创建表分区
  • sqli-labs靶场第七关——文件导出注入
  • python 如何遍历 postgresql 所有的用户表 ?
  • PostgreSQL 联合索引生效条件
  • 每日Prompt:磨砂玻璃后的虚实对比剪影
  • 如何在WooCommerce中设置Stripe
  • 【匹配】Needleman–Wunsch
  • 【yolo】如何在 YOLOv8 中添加负样本以减少误检
  • Springboot3自定义starter笔记
  • 赡养纠纷个案推动类案监督,检察机关保障特殊群体胜诉权
  • “大型翻车现场”科技满满,黄骅打造现代化港口和沿海新城典范
  • 十年磨一剑!上海科学家首次揭示宿主识别肠道菌群调控免疫新机制
  • 陕西旱情实探:大型灌区农业供水有保障,大旱之年无旱象
  • MSCI中国指数5月调整:新增5只A股、1只港股
  • 央媒评网红质疑胖东来玉石定价暴利:对碰瓷式维权不能姑息