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

 更新时间:2019年10月28日 09:54:44   作者:haeasringnar  
今天小编就为大家分享一篇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按钮不可点击状态就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • Vue.js页面验证跳转功能实现

    Vue.js页面验证跳转功能实现

    这篇文章主要介绍了Vue.js页面验证跳转功能实现,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧
    2024-04-04
  • vue使用iview的modal弹窗嵌套modal出现格式错误的解决

    vue使用iview的modal弹窗嵌套modal出现格式错误的解决

    这篇文章主要介绍了vue使用iview的modal弹窗嵌套modal出现格式错误的解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-09-09
  • vue实现横向时间轴

    vue实现横向时间轴

    这篇文章主要为大家详细介绍了vue实现横向时间轴,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-02-02
  • vue中利用simplemde实现markdown编辑器(增加图片上传功能)

    vue中利用simplemde实现markdown编辑器(增加图片上传功能)

    这篇文章主要介绍了vue中利用simplemde实现markdown编辑器(增加图片上传功能),本文通过实例代码相结合的形式给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-04-04
  • Vue h函数的使用详解

    Vue h函数的使用详解

    本文主要介绍了Vue h函数的使用详解,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-12-12
  • webpack vue 项目打包生成的文件,资源文件报404问题的修复方法(总结篇)

    webpack vue 项目打包生成的文件,资源文件报404问题的修复方法(总结篇)

    这篇文章主要介绍了解决webpack vue 项目打包生成的文件,资源文件报404问题的修复方法,需要的朋友可以参考下
    2018-01-01
  • Vue集成百度地图实现位置选择功能

    Vue集成百度地图实现位置选择功能

    由于添加门店时,需要选择门店的省、市、区、详细地址、以及门店的经纬度信息,本文给大家分享Vue集成百度地图实现位置选择功能,感兴趣的朋友一起看看吧
    2022-06-06
  • Vuex之Action的使用方法详解

    Vuex之Action的使用方法详解

    这篇文章主要介绍了Vuex之Action的使用方法详解,Action 类似于 mutation ,不同在于Action 提交的是 mutation,而不是直接变更状态,
    Action 可以包含任意异步操作,需要的朋友可以参考下
    2023-11-11
  • 基于Vue制作组织架构树组件

    基于Vue制作组织架构树组件

    最近公司在做一个基于vue开发的项目,项目需要开发一个展示组织架构的树组件,在网上搜了半天,没有找到合适的,下面小编给大家分享一个基于Vue制作组织架构树组件,需要的朋友参考下吧
    2017-12-12
  • webpack4+express+mongodb+vue实现增删改查的示例

    webpack4+express+mongodb+vue实现增删改查的示例

    这篇文章主要介绍了webpack4+express+mongodb+vue 实现增删改查的示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-11-11

最新评论