TNBLOG
首页
博客
视频
资源
问答
猿趣
手机
关于
搜索
收藏
便签
笔记
消息
创作
登录
剑轩
故如虹,知恩;故如月,知明
博主信息
排名
6
文章
6
粉丝
16
评论
8
文章类别
CSS
15篇
微服务
41篇
Git
14篇
.NET
102篇
移动开发
33篇
软件架构
23篇
.NET Core
119篇
.NET MVC
11篇
英语
3篇
随笔
86篇
Bootstrap
3篇
Redis
21篇
编辑器
10篇
Js相关
15篇
虚拟化
8篇
更多
Oracle
7篇
Python
14篇
数据库
26篇
EF
17篇
微信
3篇
前端
151篇
消息队列
6篇
docker
41篇
多线程
1篇
Java
4篇
软件基础
2篇
C++
2篇
WCF
7篇
Linux
7篇
nginx
5篇
K8S
9篇
ABP
2篇
最新文章
最新评价
{{item.articleTitle}}
{{item.blogName}}
:
{{item.content}}
关于我们
ICP备案 :
渝ICP备18016597号-1
网站信息:
2018-2024
TNBLOG.NET
技术交流:
群号656732739
联系我们:
contact@tnblog.net
欢迎加群
欢迎加群交流技术
原
vue根据文件地址下载文件。vue下载文件的时候给header传递token
2575
人阅读
2020/1/16 10:19
总访问:
3918456
评论:
0
收藏:
0
手机
分类:
前端
**最简单的方式一句话搞定** ``` window.location.href = res.success.url ``` **动态创建a标签触发点击事件** ``` //根据文件地址下载文件 downLoadByUrL(fileUrlInp,fileNameInp){ let url = fileUrlInp const a = document.createElement('a') a.href = url //下载的文件地址 a.download = fileNameInp // 下载后文件名 a.style.display = 'none' document.body.appendChild(a) a.click() // 点击下载 document.body.removeChild(a) // 下载完成移除元素 } ``` 使用 ``` //下载实验资料 downLoadResource() { const _this = this //通过实验id获取实验素材的url地址 _this.$http.get('/oss/api/SmartFiles/GetFileUrl', { fileId: _this.fileId, downloadName: "素材" }).then(res => { if(res.code==0) { //根据返回的实验素材url地址去下载 _this.downLoadByUrL(res.data.url,"素材") } }) }, ``` **如果使用a标签下载跨域,可以使用下面的方法** ``` const fileurl = fileUrlInp.replace(/(http|https):/, '') window.open(fileurl) ``` **当然还有其他方法比如:** ``` const downloadRes = async () => { let response = await fetch(url); let blob = await response.blob(); let objectUrl = window.URL.createObjectURL(blob); let a = document.createElement('a'); a.href = objectUrl; a.download = res.success.fileName; a.click() a.remove(); } downloadRes(); ``` **vue下载文件的时候给header传递token** 参考:https://www.tnblog.net/aojiancc2/article/details/7969
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739
👈{{preArticle.title}}
👉{{nextArticle.title}}
评价
{{titleitem}}
{{titleitem}}
{{item.content}}
{{titleitem}}
{{titleitem}}
{{item.content}}