import{o as a,a as t,y as n}from"./vue-libs.b44bc779.js";const e={class:"van-doc-markdown-body"},r=n(`

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

AttributeDescriptionTypeDefault
valuePassword valuestring''
infoBottom infostring-
error-infoBottom error infostring-
lengthMaxlength of passwordnumber | string6
gutterGutter of inputnumber | string0
maskWhether to mask valuebooleantrue
focusedWhether to show focused cursorbooleanfalse

Events

EventDescriptionArguments
focusEmitted when input is focused-

Types

The component exports the following type definitions:

import type { 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-border-radius6px-
--van-password-input-background-colorvar(--van-background-color-light)-
--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-animation-duration1s-
`,15),l=[r],i={__name:"README",setup(o,{expose:s}){return s({frontmatter:{}}),(d,c)=>(a(),t("div",e,l))}};export{i as default};