vue-獲取驗證碼

image.png
<el-col :span="16"><el-input placeholder="請輸入手機號碼" v-model="innerVisibleForm2.PhoneNum2"></el-input></el-col>
<el-col :span="16" v-show="verShow"><el-button @click="GetCode()" type="primary">獲取驗證碼</el-button></el-col>
<el-col :span="16" v-show="!verShow"><el-button disabled type="info"><span>{{timer}}</span>秒后重新獲取</el-button></el-col>
data () {
    verShow: true, // 判斷顯示那個按鈕
    timer: 60, // 短信驗證碼倒計時
}

this.innerVisibleForm2.PhoneNum2是input內(nèi)容

methods: {
    GetCode () {
      const regEmali = /^(0|86|17951)?(13[0-9]|15[0123456789]|17[678]|18[0-9]|14[57])[0-9]{8}$/
      if (regEmali.test(this.innerVisibleForm2.PhoneNum2)) {
        this.verShow = false
        const authTimer = setInterval(() => {
          this.timer--
          if (this.timer <= 0) {
            this.verShow = true
            this.timer = 60
            clearInterval(authTimer)
          }
        }, 1000)
      } else {
        this.$message.error('請輸入合法手機')
      }
    },
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容