工作记录
后端传回的验证码格式是arraybuffer格式,需要将其转换成二进制,再转换成base64格式的图片
axios
export const getVerificationCode = () => {
return service({
method: 'post',
url: "/api/sysUser/image",
responseType: 'arraybuffer'
})
}
js
html:
<img class="codeimg" :src="imgSrc" @click="getImage">
首先在调用一次
created() {
this.getImage()
},
data:
imgSrc: '',
方法:
async getImage() {
let res = await getVerificationCode();
let array = res.data;
let imageData = "data:image/png;base64," + btoa(
new Uint8Array(array).reduce(
(data, byte) => data + String.fromCharCode(byte), ""
)
)
this.imgSrc = imageData;
}
|