当前位置: 首页 > 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: () => '',};}}
}

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

http://www.xdnf.cn/news/469369.html

相关文章:

  • 亚马逊,temu测评采购低成本养号策略:如何用一台设备安全批量管理买家账号
  • 英语学习笔记
  • 移动端网络调试全流程:从常见抓包工具到Sniffmaster 的实战体验
  • Web》》url 参数 # 、 ? 、@
  • manuskript开源程序是面向作家的开源工具
  • Cursor vs VS Code vs Zed
  • deepseek讲解如何快速解决内存泄露,内存溢出问题
  • 拉取sset docker镜像
  • 经典卷积神经网络
  • 【Java ee初阶】http(1)
  • 【电子通识】热敏纸定义、分类与内在质量
  • 无人机避障——深蓝学院浙大Fast-planner学习部分(前端部分)
  • Java JSON 数据绑定对象的注意事项
  • 【FMC216】基于 VITA57.1 的 2 路 TLK2711 发送、2 路 TLK2711 接收 FMC 子卡模块
  • iOS性能调优实践:我常用的工具与流程(含克魔 KeyMob 使用体验)
  • 养生:健康生活的核心策略
  • mysqlbinlog用法详解
  • 广东省省考备考(第十一天5.15)—言语(第四节课)
  • 220V转24V非隔离恒压芯片WT5105
  • 算法题(147):纪念品分组
  • 华为开源自研AI框架昇思MindSpore应用案例:小型CNN模型之SqueezeNet网络
  • 网络安全-等级保护(等保) 2-4 GB/T 22239-2019 《信息安全技术 网络安全等级保护基础要求》-2019-05-10发布【现行】
  • 多平台图标设计与管理的终极解决方案
  • 2025年软件测试面试题,精选33道,附答案
  • Kafka消费者分组机制深度解析
  • 配置VScodePython环境Python was not found;
  • DataHub:现代化元数据管理的核心平台与应用实践
  • Linux 托盘图标显示位置异常
  • ubuntu18 设置静态ip
  • PyGame游戏开发(入门知识+组件拆分+历史存档/回放+人机策略)