umijs / qiankun

📦 🚀 Blazing fast, simple and complete solution for micro frontends.
https://qiankun.umijs.org
MIT License
15.85k stars 2.02k forks source link

[Bug]引入BMapGL以后无法使用 #2260

Closed IronRookie closed 2 years ago

IronRookie commented 2 years ago
  const BMapGL = (window as any).BMapGL
  const map = new BMapGL.Map('map_container')

如代码所示,子应用是这么用的,但是接入主应用以后,会报错,Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'Map'),提示window上并没有BMapGL,这个时候应该怎么解决了

     async fetch (url, ...args) {
        if (['baidu.com'].some(item => url.includes(item))) {
          return {
            async text () {
              return ''
            }
          }
        }
        return window.fetch(url, ...args)
      }

之前为了解决跨域报错,设置了fetch函数

gongshun commented 2 years ago

百度地图问题解决方案:

  1. 主应用加载百度地图js,子应用直接使用
  2. 子应用异步加载百度地图js,然后用 excludeAssetFilter 过滤,参考 https://github.com/umijs/qiankun/issues/812