zoukankan      html  css  js  c++  java
  • 23、vue实现获取短信验证码

    1、html页面:

                <el-form-item  prop="phoneCode" class="pr">
                  <el-input placeholder="短信验证码"  v-model="form.phoneCode"></el-input>
                  <button @click.prevent="getCode()"  class="code-btn" :disabled="!show">
                      <span v-show="show">获取验证码</span>
                      <span v-show="!show" class="count">{{count}} s</span>
                  </button>
                </el-form-item>
    /* 短信验证码css */
    .pr {
    position: relative;
    }
    .code-btn {
    100px;
    height: 20px;
    position: absolute;
    top: 10px;
    right: 5px;
    z-index: 222;
    color: #ef8466;
    font-size: 14px;
    border: none;
    border-left: 1px solid #bababa;
    padding-left: 10px;
    background-color: #fff;
    cursor: pointer;
    }

    2、编写方法:

        // 获取短信验证码
        getCode() {
    //axios请求 console.log(
    this.form.phone); // 验证码倒计时 if (!this.timer) { this.count = 60; this.show = false; this.timer = setInterval(() => { if (this.count > 0 && this.count <= 60) { this.count--; } else { this.show = true; clearInterval(this.timer); this.timer = null; } }, 1000); } }

     效果图:

    不存在一劳永逸的技术,唯有坚持不懈的努力.
  • 相关阅读:
    Django后台admin的使用
    $(.ajax)的使用
    centos7配置双网卡bond
    vsftpd服务的搭建
    linu重置root密码(CentOS7)
    python内置函数
    元组和字典的魔法
    列表的魔法
    字符串的魔法
    zabbix-get
  • 原文地址:https://www.cnblogs.com/xlfdqf/p/11195111.html
Copyright © 2011-2022 走看看