[ol]
[/ol]
[ol]
[/ol]
axios({ method: "get", url: item.url, responseType: "blob" })
.then((res: any) => {
if (res?.hasError) {
item.error = true;
instance.delete(item.key);
return;
}
let blob: any;
if (item.mediaType === "IMAGE_SVG" || item.mediaType === "104" || res?.headers?.["content-type"] === "image/svg+xml") {
blob = new Blob([res.data], { type: "image/svg+xml" });
} else {
blob = new Blob([res.data]);
}
el.setAttribute("src", URL.createObjectURL(blob));
instance.caches.set(item.key, { status: 1, result: URL.createObjectURL(blob), responseData: res });
// 动态获取大小
if (res?.data?.size) {
item.size = res?.data?.size;
}
item.error = false;
})
请求返回的响应信息如下:
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Cache-Control: max-age=0
Cache-Control: max-age=0
Connection: keep-alive
Content-Disposition: attachment; filename="笔记.svg"
Content-Type: application/x-download;charset=UTF-8
Date: Thu, 21 Dec 2023 14:08:30 GMT
Expires: 0
Keep-Alive: timeout=4
Pragma: no-cache
Proxy-Connection: keep-alive
Server: nginx/1.20.1
Transfer-Encoding: chunked
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-Xss-Protection: 1; mode=block
想求助下大佬们,为什么直接使用 img 标签的 src 无法显示 svg 图像?