Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

主应用无法加载子应用的图片 #9

Open
Come2BtheOne opened this issue Sep 16, 2021 · 16 comments
Open

主应用无法加载子应用的图片 #9

Come2BtheOne opened this issue Sep 16, 2021 · 16 comments

Comments

@Come2BtheOne
Copy link

主应用 http://localhost:9001
vue3子应用(vite) http://localhost:9300
复现仓库 https://github.com/Come2BtheOne/qiankunDemo.git

@tengmaoqing
Copy link
Owner

是哪一张图片加载不了呢

1、如果你是通过

<img src="/xxx.jpg">

这种是不行的,乾坤本身也还没支持到这个地步。

2、如果你是

import img from './x.jpg';
<img :src="img">

需要注意 vite.config.ts 写完整的base

@Come2BtheOne
Copy link
Author

是哪一张图片加载不了呢

1、如果你是通过

<img src="/xxx.jpg">

这种是不行的,乾坤本身也还没支持到这个地步。

2、如果你是

import img from './x.jpg';
<img :src="img">

需要注意 vite.config.ts 写完整的base

图片用的是第二种引入方式。
配置了完整的base。但还是请求主应用的资源
微信截图_20210924095346

@fonglezen
Copy link

是哪一张图片加载不了呢
1、如果你是通过

<img src="/xxx.jpg">

这种是不行的,乾坤本身也还没支持到这个地步。
2、如果你是

import img from './x.jpg';
<img :src="img">

需要注意 vite.config.ts 写完整的base

图片用的是第二种引入方式。
配置了完整的base。但还是请求主应用的资源
微信截图_20210924095346

vite 目前在development模式的时候,base设置了之后是不生效的。你可以关注vite 后续是否会支持,在vite issue里看到有人提了这个问题了。

@Come2BtheOne
Copy link
Author

Come2BtheOne commented Oct 9, 2021

vite 目前在development模式的时候,base设置了之后是不生效的。你可以关注vite 后续是否会支持,在vite issue里看到有人提了这个问题了。

好的。感谢回答!

@Soya-xy
Copy link

Soya-xy commented Nov 2, 2021

可添加以下下配置解决

  server: {
    origin:"子应用地址",
  }

@wishong
Copy link

wishong commented Dec 11, 2021

server: {
origin:"子应用地址",
}

这个好像不起作用

@Come2BtheOne
Copy link
Author

我试了有效。你是怎么写的?

@wishong
Copy link

wishong commented Dec 13, 2021

我试了有效。你是怎么写的?

子应用的vite.config
server: {
origin:"http://localhost:4000",
}

@binyellow
Copy link

我试了有效。你是怎么写的?

serve.origin是有效的,楼主你只需要改下你资源的引用方式就好了,图片相对路径改成@/asserts/logo.png就正常了

@xianmxcv
Copy link

所以子应用css的图片就没救了么

@wishong
Copy link

wishong commented Mar 10, 2022

所以子应用css的图片就没救了么

有用的,路径要拼写完全,最后多加一个 / 就行
server: {
origin:"http://localhost:4000/",
}

@xianmxcv
Copy link

所以子应用css的图片就没救了么

有用的,路径要拼写完全,最后多加一个 / 就行 server: { origin:"http://localhost:4000/", }

嗯嗯,这样子在开发环境能行。生产环境呢,将图片打包到主应用里或者全转为base64吗

@qw789
Copy link

qw789 commented May 27, 2022

"http://

加/ vite 会报提示啊,server.origin should not end with "/". Using "http://localhost:7105" instead.

@summerbiu
Copy link

我试了有效。你是怎么写的?

serve.origin是有效的,楼主你只需要改下你资源的引用方式就好了,图片相对路径改成@/asserts/logo.png就正常了

貌似不适用于用:src动态赋值图片

@rookiePrgrmer
Copy link

所以子应用css的图片就没救了么

有用的,路径要拼写完全,最后多加一个 / 就行 server: { origin:"http://localhost:4000/", }

嗯嗯,这样子在开发环境能行。生产环境呢,将图片打包到主应用里或者全转为base64

所以生产环境打包可以支持吗?

@wyodyia
Copy link

wyodyia commented Dec 7, 2023

所以子应用css的图片就没救了么

有用的,路径要拼写完全,最后多加一个 / 就行 server: { origin:"http://localhost:4000/", }

嗯嗯,这样子在开发环境能行。生产环境呢,将图片打包到主应用里或者全转为base64

所以生产环境打包可以支持吗?

YES

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests