问题
请求后端接口,返回的是一大串,如何在img显示出来?
解决方法
1.设置axios responseType: 'blob'
2.直接createObjectURL
export function flowExample(data) {
return request({
url: '......',
method: 'get',
params:data,
responseType: 'blob'
})
}
flowExample(data).then(res=>{
var img = document.createElement('img')
const myBlob = new window.Blob([res], {type: 'image/jpeg'})
const qrUrl = window.URL.createObjectURL(myBlob)
img.src = qrUrl
img.onload = function () {
window.URL.revokeObjectURL(qrUrl)
}
const imgDiv = document.querySelector('#flow-img')
imgDiv.appendChild(img)
})