W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
帶網(wǎng)格的輸入框組件,可以用于輸入支付密碼、短信驗證碼等,通常與數(shù)字鍵盤組件配合使用
import Vue from 'vue';
import { PasswordInput, NumberKeyboard } from 'vant';
Vue.use(PasswordInput);
Vue.use(NumberKeyboard);
<!-- 密碼輸入框 -->
<van-password-input
:value="value"
info="密碼為 6 位數(shù)字"
:focused="showKeyboard"
@focus="showKeyboard = true"
/>
<!-- 數(shù)字鍵盤 -->
<van-number-keyboard
:show="showKeyboard"
@input="onInput"
@delete="onDelete"
@blur="showKeyboard = false"
/>
export default {
data() {
return {
value: '123',
showKeyboard: true
};
},
methods: {
onInput(key) {
this.value = (this.value + key).slice(0, 6);
},
onDelete() {
this.value = this.value.slice(0, this.value.length - 1);
}
}
}
<van-password-input
:value="value"
:length="4"
:gutter="15"
:focused="showKeyboard"
@focus="showKeyboard = true"
/>
<van-password-input
:value="value"
:mask="false"
:focused="showKeyboard"
@focus="showKeyboard = true"
/>
通過error-info屬性可以設置錯誤提示信息,例如當輸入六位時提示密碼錯誤
<!-- 密碼輸入框 -->
<van-password-input
:value="value"
:error-info="errorInfo"
:focused="showKeyboard"
@focus="showKeyboard = true"
/>
<!-- 數(shù)字鍵盤 -->
<van-number-keyboard
:show="showKeyboard"
@input="onInput"
@delete="onDelete"
@blur="showKeyboard = false"
/>
export default {
data() {
return {
value: '123',
showKeyboard: true,
errorInfo: ''
};
},
methods: {
onInput(key) {
this.value = (this.value + key).slice(0, 6);
if (this.value.length === 6) {
this.errorInfo = '密碼錯誤';
} else {
this.errorInfo = '';
}
},
onDelete() {
this.value = this.value.slice(0, this.value.length - 1);
}
}
}
參數(shù) | 說明 | 類型 | 默認值 |
---|---|---|---|
value | 密碼值 | string | '' |
info | 輸入框下方文字提示 | string | - |
error-info | 輸入框下方錯誤提示 | string | - |
length | 密碼最大長度 | number | string | 6 |
gutter | 輸入框格子之間的間距,如 20px 2em ,默認單位為px | number | string | 0 |
mask | 是否隱藏密碼內(nèi)容 | boolean | true |
focused v2.1.8 | 是否已聚焦,聚焦時會顯示光標 | boolean | false |
事件名 | 說明 | 回調(diào)參數(shù) |
---|---|---|
focus | 輸入框聚焦時觸發(fā) | - |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: