js处理后端返回的图片二进制流
vue axios async/await FileReader
例:<img :src="imgSrc"><button @click="handleBtn">
getUrl (apiUrl, params) {
return axios({
url: apiUrl,
method: 'get',
responseType: 'blob',
params
})
},
async handleBtn () {
let that = this
let params = {}
let data = await this.getUrl("/getQRcode", params)
let blob = data.data;
let reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = function (e) {
let url = e.target.result;
that.imgSrc = url
that.flag = true
}
}