-
Notifications
You must be signed in to change notification settings - Fork 121
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
Comments
跨域不是客户端能处理的,也要服务端支持访问的 |
可以通过请求拿到图片的二进制数据,然后写入到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
加载不同域名下的图片,想问问有办法解决跨域请求吗。
谢谢。
The text was updated successfully, but these errors were encountered: