網(wǎng)站首頁 編程語言 正文
如圖,后端返回的svg內(nèi)容直接是一個(gè)xml文件。
需要前端進(jìn)行展示并下載。
前端有兩個(gè)功能,一個(gè)是預(yù)覽(在瀏覽器中打開svg),一個(gè)是下載(將svg下載到本地)
預(yù)覽的代碼:
this.showDataByBlob(data, { type: 'image/svg+xml' }) // data里就是我上邊截圖的xml內(nèi)容
showDataByBlob(data, options) {
const blob = new Blob([data], options)
const href = window.URL.createObjectURL(blob)
window.open(href)
},
這樣就能將svg在瀏覽器中打開啦!
效果如圖:
下載的代碼:
this.exportDataByBlob(data, { type: 'image/svg+xml' }, 'test.svg')
exportDataByBlob(data, options, fileName) {
const blob = new Blob([data], options)
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)
downloadElement.href = href
downloadElement.download = fileName
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement)
window.URL.revokeObjectURL(href)
},
效果如下:
原文鏈接:https://blog.csdn.net/changyana/article/details/130333251
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2022-04-06 Android中卡頓優(yōu)化布局詳細(xì)介紹_Android
- 2022-05-12 python2中input()漏洞
- 2022-04-03 ?Python?代碼制作動(dòng)態(tài)鞭炮_python
- 2022-08-11 Redis實(shí)現(xiàn)主從復(fù)制方式(Master&Slave)_Redis
- 2023-07-06 Mac安裝python3并配置環(huán)境變量
- 2022-12-31 一文初探Go語言中的reflect反射包_Golang
- 2022-12-29 基于Python寫一個(gè)番茄鐘小工具_(dá)python
- 2023-12-26 Mapper.xml文件中SQL新增數(shù)據(jù)的簡(jiǎn)便寫法
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支