PasswordInput - Vant 4
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.
js
import { createApp } from'vue'; import { PasswordInput, NumberKeyboard } from'vant'; const app = createApp(); app.use(PasswordInput); app.use(NumberKeyboard);Usage
Basic Usage
html
js
import { ref } from'vue'; exportdefault { setup() { const value = ref('123'); const showKeyboard = ref(true); return { value, showKeyboard, }; }, };Custom Length
html
Add Gutter
html
Without Mask
html
Hint Error
Use info to set info message, use error-info prop to set error message.
html
js
import { ref, watch } from'vue'; exportdefault { 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* |
| gutter | Gutter of input | *number | string* |
| 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 | - |
Types
The component exports the following type definitions:
ts
importtype { PasswordInputProps } from'vant';Theming
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-radius | 6px | - |
| --van-password-input-background | var(--van-background-2) | - |
| --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-duration | 1s | - |