mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
PasswordInput
Intro
The passwordinput component is usually used with NumberKeyboard Component.
Install
Register component globally via app.use
, refer to Component Registration for more registration ways.
import { createApp } from 'vue';
import { PasswordInput, NumberKeyboard } from 'vant';
const app = createApp();
app.use(PasswordInput);
app.use(NumberKeyboard);
Usage
Basic Usage
<van-password-input
:value="value"
:focused="showKeyboard"
@focus="showKeyboard = true"
/>
<van-number-keyboard
v-model="value"
:show="showKeyboard"
@blur="showKeyboard = false"
/>
import { ref } from 'vue';
export default {
setup() {
const value = ref('123');
const showKeyboard = ref(true);
return {
value,
showKeyboard,
};
},
};
Custom Length
<van-password-input
:value="value"
:gutter="15"
:focused="showKeyboard"
@focus="showKeyboard = true"
/>
Add Gutter
<van-password-input
:value="value"
:gutter="10"
:focused="showKeyboard"
@focus="showKeyboard = true"
/>
Without Mask
<van-password-input
:value="value"
:mask="false"
:focused="showKeyboard"
@focus="showKeyboard = true"
/>
Hint Error
Use info
to set info message, use error-info
prop to set error message.
<van-password-input
:value="value"
info="Some tips"
:error-info="errorInfo"
:focused="showKeyboard"
@focus="showKeyboard = true"
/>
<van-number-keyboard
v-model="value"
:show="showKeyboard"
@blur="showKeyboard = false"
/>
import { ref, watch } from 'vue';
export default {
setup() {
const value = ref('123');
const errorInfo = ref('');
const showKeyboard = ref(true);
watch(value, (newVal) => {
if (newVal.length === 6 && newVal !== '123456') {
errorInfo.value = 'Password Mistake';
} else {
errorInfo.value = '';
}
});
return {
value,
errorInfo,
showKeyboard,
};
},
};
API
Props
Attribute | Description | Type | Default |
---|---|---|---|
value | Password value | string | '' |
info | Bottom info | string | - |
error-info | Bottom error info | string | - |
length | Maxlength of password | number | string | 6 |
gutter | Gutter of input | number | string | 0 |
mask | Whether to mask value | boolean | true |
focused | Whether to show focused cursor | boolean | false |
Events
Event | Description | Arguments |
---|---|---|
focus | Emitted when input is focused | - |
CSS Variables
The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
Name | Default Value | Description |
---|---|---|
--van-password-input-height | 50px | - |
--van-password-input-margin | 0 var(--van-padding-md) | - |
--van-password-input-font-size | 20px | - |
--van-password-input-border-radius | 6px | - |
--van-password-input-background-color | var(--van-white) | - |
--van-password-input-info-color | var(--van-gray-6) | - |
--van-password-input-info-font-size | var(--van-font-size-md) | - |
--van-password-input-error-info-color | var(--van-danger-color) | - |
--van-password-input-dot-size | 10px | - |
--van-password-input-dot-color | var(--van-black) | - |
--van-password-input-cursor-color | var(--van-text-color) | - |
--van-password-input-cursor-width | 1px | - |
--van-password-input-cursor-height | 40% | - |
--van-password-input-cursor-animation-duration | 1s | - |