Vuetify —— 实现图形验证码

在这里插入图片描述
调取接口,后端返回的图形验证码数据格式是base64图片路径,根据其数据将其渲染值页面中

在这里插入图片描述

<v-row v-if="showCaptcha">
  <v-col class="px-0" cols="12" style="position: relative">
    <v-text-field
      solo
      label="请输入图形验证码"
      prepend-inner-icon="mdi-check-circle-outline"
      v-model="verify_code"
      required
      :rules="rules.isFull"
    ></v-text-field>
    <img
      style="position: absolute; top: 4px; right: 4px"
      :src="captcha_image"
      alt=""
    />
  </v-col>
</v-row>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的登录页示例,使用了 Vuetify 组件和 Axios 进行登录验证: ```html <template> <v-container> <v-card> <v-card-title class="text-h5">登录</v-card-title> <v-card-text> <v-form @submit.prevent="login"> <v-text-field label="用户名" v-model="username" required></v-text-field> <v-text-field label="密码" v-model="password" type="password" required></v-text-field> <v-row> <v-col cols="6"> <v-text-field label="验证码" v-model="captcha" required></v-text-field> </v-col> <v-col cols="6"> <img :src="captchaUrl" @click="refreshCaptcha" style="cursor: pointer;"> </v-col> </v-row> <v-btn type="submit" color="primary">登录</v-btn> </v-form> </v-card-text> </v-card> </v-container> </template> <script> import axios from 'axios'; export default { data() { return { username: '', password: '', captcha: '', captchaUrl: '', } }, created() { this.refreshCaptcha(); }, methods: { refreshCaptcha() { this.captchaUrl = '/api/captcha?' + new Date().getTime(); }, login() { axios.post('/api/login', { username: this.username, password: this.password, captcha: this.captcha, }).then(response => { // 登录成功 console.log(response.data); this.$router.push('/'); }).catch(error => { // 登录失败 console.log(error.response.data); this.refreshCaptcha(); }); }, }, } </script> ``` 其中,`v-text-field` 组件用于输入用户名、密码和验证码,`v-btn` 组件用于提交登录表单。`captchaUrl` 和 `refreshCaptcha` 方法用于获取和刷新验证码图片。在登录成功后,可以使用 `this.$router.push()` 方法跳转到其他页面。 注意,在实际应用中,需要使用后端 API 来处理登录和验证码的验证。本示例中,假设后端 API 为 `/api/login` 和 `/api/captcha`。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值