vue验证码组件使用方法详解

2022-04-15 0 730

本文实例为大家分享了vue验证码组件使用的具体实现代码,供大家参考,具体内容如下

代码如下:

<template>

     <div class="join_formitem">
       <label class="enquiry">验证码<span>:</span></label>
       <div class="captcha">
         <input type="text" placeholder="请输入验证码" class="yanzhengma_input" v-model="picLyanzhengma" />
         <input type="button" @click="createdCode" class="verification" v-model="checkCode" />
       </div>
    </div>
</template>

<script>
export default {
  data(){
    return{
      code:'',
      checkCode:'',                   
      picLyanzhengma:''         //..验证码图片
    }
  },
  created(){
    this.createdCode()
  },
  methods: {
    // 图片验证码
    createdCode(){
      // 先清空验证码输入
      this.code = ""
      this.checkCode = ""
      this.picLyanzhengma = ""
      // 验证码长度
      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>
.yanzhengma_input{
  font-family: 'Exo 2',sans-serif;
  border: 1px solid #fff;
  color: #fff;
  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验证码组件使用方法详解

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持NICE源码。

免责声明:
1、本网站所有发布的源码、软件和资料均为收集各大资源网站整理而来;仅限用于学习和研究目的,您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。 不得使用于非法商业用途,不得违反国家法律。否则后果自负!

2、本站信息来自网络,版权争议与本站无关。一切关于该资源商业行为与www.niceym.com无关。
如果您喜欢该程序,请支持正版源码、软件,购买注册,得到更好的正版服务。
如有侵犯你版权的,请邮件与我们联系处理(邮箱:skknet@qq.com),本站将立即改正。

NICE源码网 JavaScript vue验证码组件使用方法详解 https://www.niceym.com/29830.html