假如二维码后台传的是图片流,前端展示图片
代码语言:javascript复制// 获取二维码图片
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属性
});
},
代码语言:javascript复制<img :src="imgUrl" alt="二维码图片" v-show="showCode" class="QRcode" />