1.后端开发验证码接口:
返回如下
image.png
2.后端接口返回验证图片,前端使用blob绑定在img的src上
// vue组件
<img :src="imCode" @click="getCode" />
// data中定义
data:{
imCode: {}
}
// js定义方法
const captchaAxios = Axios.create({
baseURL: '',
responseType: 'blob', //定义请求的返回类型
});
// methods中定义验证码获取的方法
getCode() {
captchaAxios.get('/verificationCode').then((res) => {
this.imCode = window.URL.createObjectURL(res.data);
});
},