vue 验证码界面实现点击后标灰并设置div按钮不可点击状态

1、先看看效果图

未点击获取验证码的按钮状态

点击后的不可点击状态

2、代码实现

<template>
 <div class="my-code">
   <input class="my-code-input" type="text" v-model="login_form.captcha" placeholder="Your Captcha">
   <div class="my-code-get" @click="get_captcha" id="new_yan">
     <span v-show="show">Get Captcha</span>
     <span v-show="!show">{{ count }} s</span>
   </div>
 </div>
</template>

<script>
  import store from '@/store'
  import Vue from 'vue'
  import $ from 'jquery'

  export default {
    name: "register",
    data () {
      return {
        show: true,
        count: 60,
        timer: null,
      }
    },
    methods: {
      get_captcha() {
         if (this.login_form.username === '' ) {
          alert('Phone number or mailbox cannot be empty')
        } else {
          if(this.timer == null){
            getValidate(this.login_form.username).then(response => {
              const data = response.data
              console.log(data)
              console.log('成功')
            }).catch(error => {
              console.log(error)
              alert(error)
            })
          }
          if (!this.timer) {
            this.count = 60;
            this.show = false;
            $(".my-code-get").addClass("huise")
            // 将鼠标设置为不可点击状态
            document.getElementById('new_yan').style.cursor = 'not-allowed'
            this.timer = setInterval(() => {
              if (this.count > 0 && this.count <= 60) {
                this.count--
              } else {
                this.show = true
                clearInterval(this.timer)
                this.timer = null
              }
            }, 1000)
          }
        }
      }
    },
    created: function() {
    },
    watch:{
      timer: function(val){
        console.log(val)
        if(val == null){
           // 监听timer变化,移除不可点击样式
          $(".my-code-get").removeClass("huise")
          document.getElementById('new_yan').style.cursor = 'pointer'
        }
      }
    }
  }
</script>

<style scoped>
  .my-input{
    text-align: left;
    display: block;
    width: 400px;
    height: 35px;
    padding: 3px;
    margin: 20px calc(50% - 200px) 20px calc(50% - 200px);
    background:none;
    outline:none;
    border:0px;
    border-bottom: 2px solid #dcdcdc;
    border-bottom-left-radius: 1px;
    border-bottom-right-radius: 1px;
    box-sizing: border-box;
    font-family: PingFangSC-Regular;
    font-size: 16px;
  }
  .my-code{
    overflow: hidden;
  }
  .my-code-get{
    float: left;
    width: 120px;
    height: 35px;
    background-color: rgb(7, 187, 127);
    margin: 0 auto 20px 0;
    line-height: 35px;
    font-family: PingFangSC-Regular;
    color: #ffffff;
    border-radius: 5px;
    -webkit-user-select:none;
    -moz-user-select:none;
    -ms-user-select:none;
    user-select:none;
  }
  .my-code-get:active{
    background-color: #0F996B;
  }
  .my-code-get:hover{
    cursor: pointer;
  }
  .my-code-input{
    float: left;
    text-align: left;
    display: block;
    width: 280px;
    height: 35px;
    padding: 3px;
    margin: 0 auto 20px calc(50% - 200px);
    background:none;
    outline:none;
    border:0px;
    border-bottom: 2px solid #dcdcdc;
    border-bottom-left-radius: 1px;
    border-bottom-right-radius: 1px;
    box-sizing: border-box;
    font-family: PingFangSC-Regular;
    font-size: 16px;
  }
  .my-code-input:focus{
    border-bottom: 2px solid #0F996B;
    border-bottom-left-radius: 1px;
    border-bottom-right-radius: 1px;
  }
  .huise{
    background-color: #dcdcdc !important;
    color: black;
  }
</style>

以上这篇vue 验证码界面实现点击后标灰并设置div按钮不可点击状态就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • Vue中添加手机验证码组件功能操作方法

    什么是组件: 组件是Vue.js最强大的功能之一.组件可以扩展HTML元素,封装可重用的代码.在较高层面上,组件是自定义的元素,Vue.js的编译器为它添加特殊功能.在有些情况下,组件也可以是原生HTML元素的形式,以is特性扩展. 写在前面: 今天要实现的功能是在 完善个人信息页面(vue)中添加手机验证码组件,当用户点击 手机选项时,弹出获取验证码组件,完成验证手机的功能: 这里考虑到功能的复用,我把当前弹出手机验证码的操作放在了单独的组件中: <template > <div>

  • VUE实现图片验证码功能

    本文实例为大家分享了VUE实现图片验证码的具体代码,供大家参考,具体内容如下 1. 概述 1.1 说明 在开发过程中,有时候需要使用图片验证码进行增加安全强度,在点击图片时更新新的图片验证码,记录此功能,以便后期使用. 2. 示例 2.1 vue示例代码 <template> <el-form style="width: 400px;"> <el-form-item style="height: 40px;margin-bottom: 20px;

  • vue实现登录页面的验证码以及验证过程解析(面向新手)

    做成之后就 是这个样子 接下来上代码 创建一个组件.显示验证码图片 <template> <div class="s-canvas"> <canvas id="s-canvas" :width="contentWidth" :height="contentHeight"></canvas> </div> </template> <script>

  • Vue写一个简单的倒计时按钮功能

    在项目开发里,我们经常会遇到发送验证码.点击了之后有60秒倒计时的按钮,很常见却也很简单,但是在写这个按钮的时候有个别地方还要注意下,今天写出来,如有问题欢迎指正! 完成的效果如下: 为了更快显示出效果,我把时间设成了5秒.按钮在点击之后会出现倒计时,同时按钮变为不可点击状态,样式也发生变化,鼠标悬浮上的样子也会发生变化. 接下来我们用代码来实现: <button class="button" @click="countDown"> {{content}

  • VUE接入腾讯验证码功能(滑块验证)备忘

    最近在用VUE做个简单的用户系统,登录注册需要验证码,想找个那种拖动的,找geetest居然已经不面向小客户了(或者说只有收费套餐). 腾讯防水墙的验证码免费使用,有2000/小时的免费额度,对于小网站完全足够了,阿里应该也有,我看discuz有插件直接能用,但没找到入口 腾讯的在这,和腾讯云无关:https://007.qq.com/captcha/#/  申请api很简单,QQ登录,创建应用,ID和secretkey就出来了,直接在文档里展示,赞一个. vue有人做了封装了geetest+腾

  • vue 验证码界面实现点击后标灰并设置div按钮不可点击状态

    1.先看看效果图 未点击获取验证码的按钮状态 点击后的不可点击状态 2.代码实现 <template> <div class="my-code"> <input class="my-code-input" type="text" v-model="login_form.captcha" placeholder="Your Captcha"> <div class=&

  • JS实现简单短信验证码界面

    1.要实现短信验证码界面,首先要有一个文本框,旁边是按钮,点击时开始倒计时. 2.先创建文本框和按钮,按钮设置对应的id,然后在js中通过id获取按钮这个元素,对其执行操作.同时应设置倒计时时间以及计时器变量,并使点击发送按钮后倒计时结束前无法继续点击按钮重新发送. 3.倒计时结束后,清除计时器,并使文字改变为"重新发送验证码",恢复对按钮能操作的功能,同时使倒计时的数从5秒重新开始以便点击后重新倒计时. <head> <meta charset="UTF-

  • 简单实现vue验证码60秒倒计时功能

    本文实例为大家分享了vue验证码倒计时60秒的具体代码,供大家参考,具体内容如下 html <span v-show="show" @click="getCode">获取验证码</span> <span v-show="!show" class="count">{{count}} s</span> js data(){ return { show: true, count: ''

  • Vue验证码60秒倒计时功能简单实例代码

    template <template> <div class='login'> <div class="loginHeader"> <input type="tel" class="loginBtn border-bottom" placeholder="请输入手机号" /> <input type="tel" class="codeBtn&q

  • Vue 防止短时间内连续点击后多次触发请求的操作

    如果连续点击提交按钮,可能会重复提交数据,导致出错,解决的方法可以使用disabled限制点击,感觉体验不是太好,所有给大家分享下面的方法 <el-button @click="throttle()">测试</el-button> export default { data(){ return { lastTime:0 //默认上一次点击时间为0 } } } methods:{ throttle(){ //获取当前时间的时间戳 let now = new Dat

  • vue实现界面滑动效果

    本文实例为大家分享了vue实现界面滑动效果的具体代码,供大家参考,具体内容如下 项目需求+效果图 1.项目需求 [点击底部导航栏,切换页面的时候,会有一个滑动的效果] 2.效果图 代码+关键代码解析 1.代码 Botnav.vue导航栏界面 <template> <div> <transition :name="transitionName"> <router-view class="Router"></rout

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

    本文实例为大家分享了vue验证码组件使用的具体实现代码,供大家参考,具体内容如下 代码如下: <template> <div class="join_formitem"> <label class="enquiry">验证码<span>:</span></label> <div class="captcha"> <input type="text&

  • vue静态界面之左二级菜单右表单表格的实例代码

    实现效果: 实现代码: <template> <div class="app-container"> <el-row :gutter="20"> <!--服务名称--> <el-col :span="4" :xs="24"> <div class="head-container"> <el-input placeholder=&q

  • Vue首页界面加载优化实现方法详解

    目录 1.路由懒加载 2.js 资源异步加载 3.图片懒加载 4.组件分包懒加载-在视口才加载 1.路由懒加载 问题: 项目在打包时会将首页与其他页面的资源打包到同一个资源文件,造成首页加载的资源文件过大. 解决方法: 路由懒加载:打包时会将每个路由页面拆分成单独的 js 资源,同时跳转到对应页面才会加载对应路由的 js 资源. { path: "/about", name: "about", component: () => import(/* webpac

  • vue项目中使用particles实现粒子背景效果及遇到的坑(按钮没有点击响应)

    为了提高页面展示效果,登录界面内容比较单一的,粒子效果作为背景经常使用到,vue工程中利用vue-particles可以很简单的实现页面的粒子背景效果. 解决问题: 以背景方式显示 无法获取按钮焦点,触发不了点击事件 实现过程 安装vue-particles npm install vue-particles --save-dev 全局配置vue-particles 在main.js里面: import VueParticles from 'vue-particles' Vue.use(VueP

随机推荐