1. 生成图片验证码接口
请求地址: /api-auth/forget/create/captchaImage
请求方式: GET
请求头:详见约定
请求参数:无
请求 URL:
GET http://localhost:8000/api-auth/forget/create/captchaImage
返回参数
参数名称
|
参数类型
|
参数说明
|
---|---|---|
img
|
String
|
图片的Base64编码
|
code
|
String
|
验证码答案
|
uuid
|
String
|
图片Id
|
2. 实现代码:
接口:
// 生成图片验证码
export function getCaptchaImage() {
return requestZhzh({
url: `/api-auth/forget/create/captchaImage`,
method: "get",
});
}
页面方法:
<el-form-item prop="code">
<p class="elFormP-srzh" prop="code">验证码</p>
<el-input v-model="formSrzh.code" type="text" auto-complete="off" placeholder="请输入图形验证码" @keyup.enter.native="handleNextSrzh" class="elFormInput-srzh" style="width:70% !important"></el-input>
<img :src="codeUrl" @click="getCode" alt="验证码" class="inputImg2-srzh" />
</el-form-item>
data(){
return{
// 输入账号--验证码
codeUrl: '',
}
}
created() {
this.getCode()
}
methods: {
// 输入账号--获取验证码
getCode() {
getCaptchaImage()
.then(res => {
this.codeUrl = 'data:image/gif;base64,' + res.data.img
this.formSrzh.uuid = res.data.uuid
})
.catch(error => {
console.error(error)
})
},
}