首页 > 其他 > 详细

后台返回字节流,前端在页面显示(如pdf/svg/img)

时间:2020-11-09 09:55:16      阅读:159      评论:0      收藏:0      [点我收藏+]

摘自:https://blog.csdn.net/sinat_39648402/article/details/105664037

Axios({
methods: ‘GET‘,
url: ‘url’,
responseType: ‘blob‘//这里意思是接收返回文件格式
}).then(res => {
let blob = new Blob([res.data], {
type: ‘text/xml‘/我这里接收的是svg 其他类型参考HTTP content-type
});
let fileURL = URL.createObjectURL(blob);
//如果你是在一个标签元素中显示这个文件,还是以我用的svg为例
//可以写成<embed src=fileURL type="text/xml" />对pdf同样适用,注意改一下type
window.open(fileURL);//这里是直接打开新窗口
});

后台返回字节流,前端在页面显示(如pdf/svg/img)

原文:https://www.cnblogs.com/modestlin/p/13946766.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!