首页 >> js开发 >> jsvue下载二进制流图片操作js大全
jsvue下载二进制流图片操作js大全
发布时间: 2021年1月13日 | 浏览:
| 分类:js开发
1、应项目要求,后台返回二进制流,而且乱码1、应项目要求,后台返回二进制流,而且乱码2、红色为必须2、红色为必须
this.$axios.post('/fishweb/agent/downLoad',this.stringify({filename:'qrCode.jpg'}), {
responseType: 'arraybuffer' //指定返回数据的格式为blob
}).then((res) => {
var src='data:image/jpg;base64,'+ btoa(new Uint8Array(res).reduce((data, byte) => data + String.fromCharCode(byte), ''));
this.srcImg = src; //图片回显
var link = document.createElement('a');
link.href = src;
link.download = "qrCode.jpg";
link.click();
})
this.$axios.post('/fishweb/agent/downLoad',this.stringify({filename:'qrCode.jpg'}), {
responseType: 'arraybuffer' //指定返回数据的格式为blob
}).then((res) => {
var src='data:image/jpg;base64,'+ btoa(new Uint8Array(res).reduce((data, byte) => data + String.fromCharCode(byte), ''));
this.srcImg = src; //图片回显
var link = document.createElement('a');
link.href = src;
link.download = "qrCode.jpg";
link.click();
})
补充知识:vue img src加载图片二进制问题记录补充知识:补充知识:vue img src加载图片二进制问题记录此 地址请求 http://xx.xx.xx.xx:xxxx/xx/.../xx/downLoadDoc?docId=xxxxx&access_token=xxxxx 返回的png二进制流。如下:在项目中我使用img src直接对图片的二进制流加载,遇到频率很高的问题是前端发起的请求被服务器多次302重定向了,然后我访问的资源存在问题。然后果断改为通过http get请求下来png 二进制流来处理。思路是通过responseType 制定返回数据格式为blob请求的图片地址 url = http://xxxxxx:xxxx/xxx/xxx/merchDoc/downLoadDoc
axios({
method: "get",
url,
params: xxx,
responseType:"blob"
}).then(response => {
this.picUrl = window.URL.createObjectURL(response);
});
axios({
method: "get",
url,
params: xxx,
responseType:"blob"
}).then(response => {
this.picUrl = window.URL.createObjectURL(response);
});解析blob 并展示在img src 中如下:
this.picUrl = window.URL.createObjectURL(response);
this.picUrl = window.URL.createObjectURL(response);以上这篇vue下载二进制流图片操作就是小编分享给大家的全部内容了,希望能给大家一个参考。
this.$axios.post('/fishweb/agent/downLoad',this.stringify({filename:'qrCode.jpg'}), {
responseType: 'arraybuffer' //指定返回数据的格式为blob
}).then((res) => {
var src='data:image/jpg;base64,'+ btoa(new Uint8Array(res).reduce((data, byte) => data + String.fromCharCode(byte), ''));
this.srcImg = src; //图片回显
var link = document.createElement('a');
link.href = src;
link.download = "qrCode.jpg";
link.click();
})
this.$axios.post('/fishweb/agent/downLoad',this.stringify({filename:'qrCode.jpg'}), {
responseType: 'arraybuffer' //指定返回数据的格式为blob
}).then((res) => {
var src='data:image/jpg;base64,'+ btoa(new Uint8Array(res).reduce((data, byte) => data + String.fromCharCode(byte), ''));
this.srcImg = src; //图片回显
var link = document.createElement('a');
link.href = src;
link.download = "qrCode.jpg";
link.click();
})
补充知识:vue img src加载图片二进制问题记录补充知识:补充知识:vue img src加载图片二进制问题记录此 地址请求 http://xx.xx.xx.xx:xxxx/xx/.../xx/downLoadDoc?docId=xxxxx&access_token=xxxxx 返回的png二进制流。如下:在项目中我使用img src直接对图片的二进制流加载,遇到频率很高的问题是前端发起的请求被服务器多次302重定向了,然后我访问的资源存在问题。然后果断改为通过http get请求下来png 二进制流来处理。思路是通过responseType 制定返回数据格式为blob请求的图片地址 url = http://xxxxxx:xxxx/xxx/xxx/merchDoc/downLoadDoc
axios({
method: "get",
url,
params: xxx,
responseType:"blob"
}).then(response => {
this.picUrl = window.URL.createObjectURL(response);
});
axios({
method: "get",
url,
params: xxx,
responseType:"blob"
}).then(response => {
this.picUrl = window.URL.createObjectURL(response);
});解析blob 并展示在img src 中如下:
this.picUrl = window.URL.createObjectURL(response);
this.picUrl = window.URL.createObjectURL(response);以上这篇vue下载二进制流图片操作就是小编分享给大家的全部内容了,希望能给大家一个参考。
相关文章:
- jsant design的table组件实现全选功能以及自定义分页js大全
- js快速解决vue2+vue-cli3项目ie兼容的问题js大全
- jsantd table按表格里的日期去排序操作js大全
- jsvue 表单输入框不支持focus及blur事件的解决方案js大全
- js小程序自定义圆形进度条js大全
- jsant design pro中可控的筛选和排序实例js大全
- jsAntd-vue Table组件添加Click事件,实现点击某行数据教程js大全
- js代码详解JavaScript执行模型
- jsvue 解决IOS10低版本白屏的问题js大全
- js如何在Express4.x中愉快地使用async的方法js大全