欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

vue验证码组件应用实例

时间:2021-04-29 10:55:46|栏目:JAVA代码|点击:

代码如下:

<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>

总结

上一篇:Java中的3种输入方式实现解析

栏    目:JAVA代码

下一篇:Java Map遍历2种实现方法代码实例

本文标题:vue验证码组件应用实例

本文地址:http://www.codeinn.net/misctech/110981.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有