how is a picture displayed in img when a request is returned from the backend interface?
To view in preview is to display a picture
console.log(img):
.]
blob createObjectURLimg
Code
this._http.doGet(this, "createQRCode", {id: this.lessonId}, (res) => {
var img = document.createElement("img")
const myBlob = new window.Blob([res.data], {type: "image/jpeg"})
console.log(myBlob)
const qrUrl = window.URL.createObjectURL(myBlob)
img.src = qrUrl
img.onload = function () {
window.URL.revokeObjectURL(qrUrl)
}
const imgDiv = document.querySelector(".qr-div")
imgDiv.appendChild(img)
})
first you need to set up axios responseType: "blob"
and then you can createObjectURL directly
const qrUrl = window.URL.createObjectURL(res.data)
var img = document.createElement("img")
img.src = qrUrl
img.onload = function () {
window.URL.revokeObjectURL(qrUrl)
}
const imgDiv = document.querySelector(".qr-div")
imgDiv.appendChild(img)