Skip to content

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

AttributeDescriptionTypeDefault
valuePassword valuestring''
infoBottom infostring-
error-infoBottom error infostring-
lengthMaxlength of password*numberstring*
gutterGutter of input*numberstring*
maskWhether to mask valuebooleantrue
focusedWhether to show focused cursorbooleanfalse

Events

EventDescriptionArguments
focusEmitted 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.

NameDefault ValueDescription
--van-password-input-height50px-
--van-password-input-margin0 var(--van-padding-md)-
--van-password-input-font-size20px-
--van-password-input-radius6px-
--van-password-input-backgroundvar(--van-background-2)-
--van-password-input-info-colorvar(--van-text-color-2)-
--van-password-input-info-font-sizevar(--van-font-size-md)-
--van-password-input-error-info-colorvar(--van-danger-color)-
--van-password-input-dot-size10px-
--van-password-input-dot-colorvar(--van-text-color)-
--van-password-input-text-colorvar(--van-text-color)-
--van-password-input-cursor-colorvar(--van-text-color)-
--van-password-input-cursor-width1px-
--van-password-input-cursor-height40%-
--van-password-input-cursor-duration1s-

Enterprise-level mobile solution based on Vant