vant/src/password-input
2021-02-26 10:24:53 +08:00
..
2021-02-14 17:07:26 +08:00
2021-02-26 10:24:53 +08:00
2021-02-02 20:31:14 +08:00
2020-10-09 20:59:27 +08:00

PasswordInput

Intro

The PasswordInput component is usually used with NumberKeyboard Component.

Install

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 -

Less Variables

How to use: Custom Theme.

Name Default Value Description
@password-input-height 50px -
@password-input-margin 0 @padding-md -
@password-input-font-size 20px -
@password-input-border-radius 6px -
@password-input-background-color @white -
@password-input-info-color @gray-6 -
@password-input-info-font-size @font-size-md -
@password-input-error-info-color @red -
@password-input-dot-size 10px -
@password-input-dot-color @black -