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-lazyload實(shí)現(xiàn)的詳細(xì)過程
本篇文章主要介紹了淺談vue-lazyload實(shí)現(xiàn)的詳細(xì)過程,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-08-08
vue?使用el-table循環(huán)輪播數(shù)據(jù)列表的實(shí)現(xiàn)
這篇文章主要介紹了vue?使用el-table循環(huán)輪播數(shù)據(jù)列表的實(shí)現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04
解決el-tree節(jié)點(diǎn)過濾不顯示下級的問題
這篇文章主要介紹了解決el-tree節(jié)點(diǎn)過濾不顯示下級的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04

