Vue仿支付寶支付功能
先給大家上個效果圖:
<div class="goods-psd"> <p class="apply-title"> 請輸入支付密碼 </p> <p style="margin: 0.2rem">確認(rèn)支付 <span>{{password}}</span> </p> <div class="psd-container"> <input class="psd-input" type="password" readonly v-for="(value,index) in passwordGroup" :key="index" :value="value.value"> </div> </div> <div class="input-pan"> <div class="pan-num" v-for="(value,num) in number" :key="num" @click="inputPsd(value)">{{value}}</div> </div> </div>
不管邏輯有沒有搞懂,先把樣式寫出來總是沒錯啦~
思路梳理
1.輸入框使用for循環(huán),循環(huán)出6個input; 2.下面的按鍵使用for循環(huán),便于后期存儲記錄; 3.將所輸入的密碼放入到pasgroup數(shù)組中; 4.定義輸入框的下標(biāo),將pasgroup數(shù)組內(nèi)容按照下標(biāo)依次放入input內(nèi); 5.開始代碼啦~
代碼
data () { return { popupVisible1: true, realInput: '', password: '111', passwordGroup: [], number: ['1','2','3','4','5','6','7','8','9','取消','0','刪除'], pasgroup: [], currentInputIndex:-1 } }
在data內(nèi)定義好我們需要的元素
initPasswordGroup () { this.passwordGroup=[]; for(var i=0;i<6;i++){ this.passwordGroup.push({ value:null }) } }
循環(huán)出input,將其內(nèi)容賦值為value:null,在界面上顯示出6個輸入框
watch: { currentInputIndex (val) { if(val == 5){ console.log(this.pasgroup) }else if(val <= -1){ this.currentInputIndex = -1 } } }
監(jiān)聽數(shù)組下標(biāo)的變化,當(dāng)下標(biāo)到5的時候打印出該數(shù)組
inputPsd (value) { switch (value) { case '取消': this.currentInputIndex = -1 this.pasgroup = [] this.initPasswordGroup () break; case '刪除': this.pasgroup.pop() console.log(this.pasgroup) // this.currentInputIndex 下標(biāo)值,刪除添加時改變 this.passwordGroup[this.currentInputIndex].value = null this.currentInputIndex-- console.log(this.passwordGroup) break; default: this.pasgroup.push(value) this.currentInputIndex++ this.passwordGroup[this.currentInputIndex].value = value } },
獲取到所點(diǎn)擊的元素,當(dāng)點(diǎn)擊‘取消'時清空input 輸入框內(nèi)的內(nèi)容,清除數(shù)組;當(dāng)點(diǎn)擊‘刪除'時,下標(biāo)值依次減減,將value重置為null; 當(dāng)點(diǎn)擊其他數(shù)字時,下標(biāo)值依次增加,將數(shù)組pasgroup[]里面的內(nèi)容寫進(jìn)passwordGroup[]里面,在輸入框中展示。
總結(jié)
以上所述是小編給大家介紹的Vue仿支付寶支付功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Vue通過配置WebSocket并實(shí)現(xiàn)群聊功能
本篇文章將與各位開發(fā)者分享下 vue-native-websocket 庫的使用以及配置,通過實(shí)例代碼給大家分享Vue通過配置WebSocket并實(shí)現(xiàn)群聊功能,需要的朋友可以參考下2019-12-12vue同一個瀏覽器登錄不同賬號數(shù)據(jù)覆蓋問題解決方案
同一個瀏覽器登錄不同賬號session一致,這就導(dǎo)致后面登錄的用戶數(shù)據(jù)會把前面登錄的用戶數(shù)據(jù)覆蓋掉,這個問題很常見,當(dāng)前我這邊解決的就是同一個瀏覽器不同窗口只能登錄一個用戶,對vue同一個瀏覽器登錄不同賬號數(shù)據(jù)覆蓋問題解決方法感興趣的朋友一起看看吧2024-01-01vue 點(diǎn)擊展開顯示更多(點(diǎn)擊收起部分隱藏)
這篇文章主要介紹了vue 點(diǎn)擊展開顯示更多(點(diǎn)擊收起部分隱藏),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04vue中如何使用embed標(biāo)簽PDF預(yù)覽
這篇文章主要介紹了vue中如何使用embed標(biāo)簽PDF預(yù)覽,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-05-05vue實(shí)現(xiàn)后臺管理權(quán)限系統(tǒng)及頂欄三級菜單顯示功能
這篇文章主要介紹了vue實(shí)現(xiàn)后臺管理權(quán)限系統(tǒng)及頂欄三級菜單顯示功能,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-06-06