vue-cli axios获取后台返回的图形验证码显示
data定义imgcodeUrl// 获取图片验证码getCodeImg() {// this.time=1234567;this.time = Date.parse(new Date());console.log("时间戳");console.log(this.time);this.axios.get(conf.api_base_url + "/validateCode/create/" + t
·
data定义imgcodeUrl
// 获取图片验证码
getCodeImg() {
// this.time=1234567;
this.time = Date.parse(new Date());
console.log("时间戳");
console.log(this.time);
this.axios.get(conf.api_base_url + "/validateCode/create/" + this.time, {
responseType: "arraybuffer"
})
.then(response => {
return 'data:image/png;base64,' + btoa(new Uint8Array(response.data).reduce((data,
byte) => data + String.fromCharCode(byte), ''));
}).then(res => {
this.imgcodeUrl = res;
})
},
使用
<img :src="imgCodeUrl" alt="图形验证码">
更多推荐
已为社区贡献6条内容
所有评论(0)