您好,登錄后才能下訂單哦!
這篇文章主要介紹vue中驗證碼界面怎么實現(xiàn)點(diǎn)擊后標(biāo)灰并設(shè)置div按鈕不可點(diǎn)擊狀態(tài),文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!
1、先看看效果圖
未點(diǎn)擊獲取驗證碼的按鈕狀態(tài)
點(diǎn)擊后的不可點(diǎn)擊狀態(tài)
2、代碼實現(xiàn)
<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") // 將鼠標(biāo)設(shè)置為不可點(diǎn)擊狀態(tài) 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){ // 監(jiān)聽timer變化,移除不可點(diǎn)擊樣式 $(".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中驗證碼界面怎么實現(xiàn)點(diǎn)擊后標(biāo)灰并設(shè)置div按鈕不可點(diǎn)擊狀態(tài)”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。