当前位置: 代码迷 >> 综合 >> [qiankun] Failed to fetch has been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘ header
  详细解决方案

[qiankun] Failed to fetch has been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘ header

热度:12   发布时间:2023-12-12 01:16:25.0

enviroment

微前端框架

qiankun

error

控制台报错

single-spa.min.js?25a2:2 Uncaught TypeError: application ‘vue2’ died in status LOADING_SOURCE_CODE: Failed to fetch has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header

reason

这个报错的意思是主应用需要拉取的子应用vue2文档不允许跨域导致而出错
个人理解这是qiankun对子应用的要求:子应用需要允许跨域

resolution

当前子应用是vue+webpack的子应用,
在dev环境下修改webpack-dev-server的配置,使其html页面允许跨域
也就是添加配置 headers: { ‘Access-Control-Allow-Origin’: ‘*’ }

如果当前vue工程有webpack-dev-server配置,则直接添加

devServer: {
    ...headers: {
     
  相关解决方案