登录页添加验证码

  1. 新建ValidCode组件

内容如下,直接copy即可:

<template><divclass="ValidCode disabled-select":style="`width:${width}; height:${height}`"@click="refreshCode"><spanv-for="(item, index) in codeList":key="index":style="getStyle(item)">{{ item.code }}</span></div>
</template>
​
<script>
export default {name: 'ValidCode',model: {prop: 'value',event: 'input'},props: {width: {type: String,default: '100px'},height: {type: String,default: '40px'},length: {type: Number,default: 4},refresh: {type: Number}},data () {return {codeList: []}},watch: {refresh () {this.createdCode()}},mounted () {this.createdCode()},methods: {refreshCode () {this.createdCode()},createdCode () {const len = this.lengthconst codeList = []const chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz0123456789'const charsLen = chars.length// 生成for (let i = 0; i < len; i++) {const rgb = [Math.round(Math.random() * 220), Math.round(Math.random() * 240), Math.round(Math.random() * 200)]codeList.push({code: chars.charAt(Math.floor(Math.random() * charsLen)),color: `rgb(${rgb})`,fontSize: `${10 + (+[Math.floor(Math.random() * 10)] + 6)}px`,padding: `${[Math.floor(Math.random() * 10)]}px`,transform: `rotate(${Math.floor(Math.random() * 90) - Math.floor(Math.random() * 90)}deg)`})}// 指向this.codeList = codeList// 将当前数据派发出去// console.log(codeList.map(item => item.code).join(''))this.$emit('input', codeList.map(item => item.code).join(''))},getStyle (data) {return `color: ${data.color}; font-size: ${data.fontSize}; padding: ${data.padding}; transform: ${data.transform}`}}
}
</script>
​
<style scoped>
.ValidCode{display: flex;justify-content: center;align-items: center;cursor: pointer;
}
.ValidCode span{display: inline-block;
}
</style>
​
  1. 在Login.vue里面新增表单

  1. 导入组件,新建变量 validCode

  1. 新增方法:createValidCode,用来接收组件传过来的验证码并赋值给data中的变量valideCode

  1. 在login方法里校验

if (!this.form.validCode) {this.$message.error("请填写验证码")return
}
if(this.form.validCode.toLowerCase() !== this.validCode.toLowerCase()) {this.$message.error("验证码错误")return
}

Vue登录页添加验证码相关推荐

  1. 为 Django admin 登录页添加验证码

    为什么80%的码农都做不了架构师?>>>    历史原因,使用上古版本 django 1.6.5,但新版本应该大同小异 首先添加自定义后台模块app, 如adm,并添加到 INSTA ...

  2. vue 登录页vue模板_Vue材质设计管理员模板

    vue 登录页vue模板 Vue材料管理员 (Vue Material Admin) Vue Material Admin Template is a Vue Based Material Desig ...

  3. Vue登录时校验验证码

    Vue登录时校验验证码 环境: 前端:Vue 后端:SpringBoot 前一章已写过如何实现验证码:https://blog.csdn.net/weixin_45732391/article/det ...

  4. cas服务器登录页面添加验证码

    本文的是以cas-4.1.5进行的,cas源代码下载官网:https://apereo.github.io/cas/4.2.x/index.html. 1.在cas工程的web.xml增加验证码功能的 ...

  5. vue项目web前端登录页数字验证码 登录流程

    1.创建code.js文件夹下面是js代码 function GVerify(options) {console.log(); // 创建一个图形验证码对象,接收options对象为参数this.co ...

  6. 登录验证---添加验证码验证,Cookie保存功能

    1,登录表单,login.jsp View Code 1 <%@ page contentType="text/html" pageEncoding="GBK&qu ...

  7. thinkphp 3.2 =》0625-6_登录业务与 验证码 =》登录页 与 验证码

    1.登录控制器  Application/Admin/Controller/ManagerController.class.php <?php /**  * Created by PhpStor ...

  8. vue登录页实现记住密码的操作

    实现记住密码的操作,如下图所示 html部分 <el-form-item style="margin-top:-10px;margin-bottom:-5px;" >& ...

  9. WordPress自定义登录和注册页面样式并且添加验证码

    通过一番尝试和验证以及网络搜索,终于实现了WordPress默认的登录和注册界面的样式修改,下面把过程记录下来.笔者主要是通过在主题中添加WordPress的钩子来实现登录和注册界面的样式修改的.Wo ...

最新文章

  1. [总结篇1]openstack neutron 中是如何做到二层隔离的
  2. office老是提示Microsoft office word 遇到问题需要关闭,问是否发送错误报告
  3. 设计上如何避免EMC问题
  4. 前端学习(531):什么是等高布局
  5. 理解x86架构的捷径
  6. 万年历插件软件测试,一个计算万年历的简单程序
  7. Fortran 注释符号
  8. C语言程序设计谭浩强第五版复习梳理3
  9. 人人接龙助手,三分钟为你的微信群创建打卡活动
  10. 查看mysql数据库密码_如何查看mysql数据库的登录名和密码
  11. 记一次对网络抖动经典案例的分析
  12. 王飞跃谈正来临的第五次工业革命:“未来一定有多个平行的你”
  13. 语音识别sdk_语音识别 sdk_离线语音识别sdk - 云+社区 - 腾讯云
  14. Python生成透明背景图片
  15. h5py基本使用教程
  16. 2021年在线教育发展趋势
  17. v-model的radio checkbox以及键盘修饰符使用
  18. 巴特沃斯滤波器、切比雪夫、椭圆滤波
  19. 判断三角形(PTA厦大慕课)
  20. html5 励志名言,经典的励志名言50句

热门文章

  1. python之判断类型
  2. tokudb_TokuDB 安装
  3. 发布网站时,80端口被占用怎么办
  4. 关于Type interface mapper.UserMapper is not known to the MapperRegistry.问题
  5. 性能测试工具工作原理
  6. SAP deliver solution 与 maintenance 的一段流水账
  7. K8S DashBoard控制台
  8. 谈谈 AI ISP (1)开场白
  9. 2021西电MoeCTF
  10. .NET平台开源项目速览(20)Newlife.Core中简单灵活的配置文件