這篇文章主要介紹了Vue如何實現支付寶支付功能,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
先給大家上個效果圖:
<div class="goods-psd"> <p class="apply-title"> 請輸入支付密碼 </p> <p >確認支付 <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循環,循環出6個input; 2.下面的按鍵使用for循環,便于后期存儲記錄; 3.將所輸入的密碼放入到pasgroup數組中; 4.定義輸入框的下標,將pasgroup數組內容按照下標依次放入input內; 5.開始代碼啦~
代碼
data () { return { popupVisible1: true, realInput: '', password: '111', passwordGroup: [], number: ['1','2','3','4','5','6','7','8','9','取消','0','刪除'], pasgroup: [], currentInputIndex:-1 } }
在data內定義好我們需要的元素
initPasswordGroup () { this.passwordGroup=[]; for(var i=0;i<6;i++){ this.passwordGroup.push({ value:null }) } }
循環出input,將其內容賦值為value:null,在界面上顯示出6個輸入框
watch: { currentInputIndex (val) { if(val == 5){ console.log(this.pasgroup) }else if(val <= -1){ this.currentInputIndex = -1 } } }
監聽數組下標的變化,當下標到5的時候打印出該數組
inputPsd (value) { switch (value) { case '取消': this.currentInputIndex = -1 this.pasgroup = [] this.initPasswordGroup () break; case '刪除': this.pasgroup.pop() console.log(this.pasgroup) // this.currentInputIndex 下標值,刪除添加時改變 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 } },
獲取到所點擊的元素,當點擊‘取消'時清空input 輸入框內的內容,清除數組;當點擊‘刪除'時,下標值依次減減,將value重置為null; 當點擊其他數字時,下標值依次增加,將數組pasgroup[]里面的內容寫進passwordGroup[]里面,在輸入框中展示。
感謝你能夠認真閱讀完這篇文章,希望小編分享的“Vue如何實現支付寶支付功能”這篇文章對大家有幫助,同時也希望大家多多支持創新互聯,關注創新互聯行業資訊頻道,更多相關知識等著你來學習!
網頁題目:Vue如何實現支付寶支付功能-創新互聯
當前網址:http://vcdvsql.cn/article6/dehdog.html
成都網站建設公司_創新互聯,為您提供網站建設、ChatGPT、靜態網站、標簽優化、軟件開發、品牌網站建設
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯