var that = this
axios
.get("接口地址", {
responseType: "arraybuffer",
params: 傳給後端的數據
})
.then(response => {
return (
"data:image/png;base64," +
btoa(
new Uint8Array(response.data).reduce(
(data, byte) => data + String.fromCharCode(byte),
""
)
)
);
})
.then(data => {
this.imgUrl = data; //賦值給img標籤的src屬性
});
費了好大勁,剛開始用什麼blob結果格式不對,又直接寫base64的也不對,直接賦值更不對了。
上面的方法可以,親測有效,responseType: "arraybuffer",很重要哦