import{o as a,a as t,y as n}from"./vue-libs.b44bc779.js";const e={class:"van-doc-markdown-body"},r=n(`
The PasswordInput component is usually used with NumberKeyboard Component.
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);
<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,
};
},
};
<van-password-input
:value="value"
:gutter="15"
:focused="showKeyboard"
@focus="showKeyboard = true"
/>
<van-password-input
:value="value"
:gutter="10"
:focused="showKeyboard"
@focus="showKeyboard = true"
/>
<van-password-input
:value="value"
:mask="false"
:focused="showKeyboard"
@focus="showKeyboard = true"
/>
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,
};
},
};
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 |
Event | Description | Arguments |
---|---|---|
focus | Emitted when input is focused | - |
The component exports the following type definitions:
import type { PasswordInputProps } from 'vant';
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-background-color-light) | - |
--van-password-input-info-color | var(--van-text-color-2) | - |
--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-text-color) | - |
--van-password-input-text-color | var(--van-text-color) | - |
--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 | - |