关于后端返回图片文档流转base64图片记录方法(axios)
关于后端返回图片文档流转base64图片记录方法(axios)
1.axios获取方法
代码如下(示例):
//请求用的axios封装的方法
//请求后台数据方法
getImg(params){
return this.$http.get(url,params,{
responseType: "arraybuffer",
})
}
// main.js import http from "@/utils/http"; Vue.prototype.$http = http;
2.调用方法
代码如下(示例):
useGetImg(){
this.$http.getImg(params).then(res=>{
if(res.status === 200){
var data =
"data:image/png;base64," + btoa(
new Uint8Array(res.data).reduce((data, byte) => data + String.fromCharCode(byte), "")
);
}
})
}
2.图片格式打印
可以发现打印后显示base64格式图片