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

加载图片为网络上的图片,现在有办法解决跨域吗。 #94

Open
yh17838 opened this issue Jul 27, 2021 · 2 comments
Open

Comments

@yh17838
Copy link

yh17838 commented Jul 27, 2021

加载不同域名下的图片,想问问有办法解决跨域请求吗。
谢谢。

@Binaryify
Copy link
Owner

Binaryify commented Oct 2, 2021

跨域不是客户端能处理的,也要服务端支持访问的

@AsherSun
Copy link

AsherSun commented Dec 31, 2021

可以通过请求拿到图片的二进制数据,然后写入到Img标签中。canvas中加载img标签。如果图片请求就是跨域的,那么需要服务端支持了

window.fetch(url).then(response => {
 respose.blob().then((result) => {
 const url = URL.createObjectURL(result);
 const image = new Image();
 image.crossOrigin = 'Anonymous'
 image.onload = () => {
  resolve({ width: image.width, height: image.height, src: url, image, });
 }
 image.onerror = reject;
 image.src = url;
 }).catch(() => null)
}).catch(() => null)

加载不同域名下的图片,想问问有办法解决跨域请求吗。 谢谢。

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

3 participants