vue验证码组件应用实例

发布时间:2020-08-30 05:43:07 作者:muzidigbig
来源:脚本之家 阅读:116

代码如下:

<template> 
  <div class="join_formitem"> 
    <label class="enquiry">验证码<span>:</span></label> 
    <div class="captcha"> 
      <input type="text" placeholder="请输入验证码" class="verification_input" v-model="picVerification" /> 
      <input type="button" @click="createdCode" class="verification" v-model="checkCode" /> 
    </div> 
  </div> 
</template> 
<script>
export default {
 data(){
  return{
   code:'',
   checkCode:'',          
   picVerification:''     //..验证码图片
  }
 },
 created(){
  this.createdCode()
 },
 methods: {
  // 图片验证码
  createdCode(){
   // 先清空验证码输入
   this.code = ""
   this.checkCode = ""
   this.picVerification = ""
   // 验证码长度
   const codeLength = 4
   // 随机数
   const random = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z')
   for(let i = 0;i < codeLength;i++){
    // 取得随机数的索引(0~35)
    let index = Math.floor(Math.random() * 36)
    // 根据索引取得随机数加到code上
    this.code += random[index]
   }
   // 把code值赋给验证码
   this.checkCode = this.code
  }
 }
}
</script> 
<style>
.verification_input{
 font-family: 'Exo 2',sans-serif;
 border: 1px solid #fff;
 color: black;
 outline: none;
 border-radius: 12px;
 letter-spacing: 1px;
 font-size: 17px;
 font-weight: normal;
 background-color: rgba(82,56,76,.15);
 padding: 5px 0 5px 10px;
 margin-left: 30px;
 height: 30px;
 margin-top: 25px;
 border: 1px solid #e6e6e6;
}
.verification{
 border-radius: 12px;
 width: 100px;
 letter-spacing: 5px;
 margin-left: 50px;
 height: 40px;
 transform: translate(-15px,0);
}
.captcha{
 height:50px;
 text-align: justify;
}
</style>

vue验证码组件应用实例

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对亿速云的支持。如果你想了解更多相关内容请查看下面相关链接

推荐阅读:
  1. 怎么在vue中封装一个随机验证码组件
  2. vue如何获取验证码倒计时组件

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vue 验证码 组件

上一篇:js获取浏览器和屏幕的各种宽度高度

下一篇:Centos7安装和配置Mysql5.7

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》