假如二维码后台传的是图片流,前端展示图片
// 获取二维码图片
getCodeImg() {
this.getUUID();
let UUID = window.sessionStorage.getItem("UUID");
this.$axios
.get("getImg", {
responseType: "arraybuffer",
params: { clientId: UUID }
})
.then(res => {
return (
"data:image/png;base64," +
btoa(
new Uint8Array(res.data).reduce(
// String.fromCharCode() 可接受一个指定的 Unicode 值,然后返回一个字符串
(data, byte) => data + String.fromCharCode(byte),
""
)
)
);
})
.then(data => {
this.imgUrl = data; //赋值给img标签的src属性
});
},
<img :src="imgUrl" alt="二维码图片" v-show="showCode" class="QRcode" />
来源:oschina
链接:https://my.oschina.net/u/2612473/blog/3274181