2020-09-28 11:46:26 +08:00

3.9 KiB
Raw Blame History

NumberKeyboard

Install

import { createApp } from 'vue';
import { NumberKeyboard } from 'vant';

const app = createApp();
app.use(NumberKeyboard);

Usage

Default Keyboard

<van-cell @touchstart.stop="show = true">
  Show Keyboard
</van-cell>
<van-number-keyboard
  :show="show"
  @blur="show = false"
  @input="onInput"
  @delete="onDelete"
/>
import { Toast } from 'vant';

export default {
  data() {
    return {
      show: true,
    };
  },
  methods: {
    onInput(value) {
      Toast(value);
    },
    onDelete() {
      Toast('delete');
    },
  },
};

Keyboard With Sidebar

<van-number-keyboard
  :show="show"
  theme="custom"
  extra-key="."
  close-button-text="Close"
  @blur="show = false"
  @input="onInput"
  @delete="onDelete"
/>

IdNumber Keyboard

Use extra-key prop to set the content of bottom left button.

<van-cell plain type="primary" @touchstart.stop="show = true">
  Show IdNumber Keyboard
</van-cell>

<van-number-keyboard
  :show="show"
  extra-key="X"
  close-button-text="Close"
  @blur="show = false"
  @input="onInput"
  @delete="onDelete"
/>

Keyboard With Title

Use title prop to set keyboard title.

<van-cell plain type="primary" @touchstart.stop="show = true">
  Show Keyboard With Title
</van-cell>
<van-number-keyboard
  :show="show"
  title="Keyboard Title"
  extra-key="."
  close-button-text="Close"
  @blur="show = false"
  @input="onInput"
  @delete="onDelete"
/>

Multiple ExtraKey

<van-cell plain type="primary" @touchstart.stop="show = true">
  Show Keyboard With Multiple ExtraKey
</van-cell>
<van-number-keyboard
  :show="show"
  :extra-key="['00', '.']"
  close-button-text="Close"
  @blur="show = false"
  @input="onInput"
  @delete="onDelete"
/>

Bind Value

<van-field readonly clickable :value="value" @touchstart.stop="show = true" />
<van-number-keyboard
  v-model="value"
  :show="show"
  :maxlength="6"
  @blur="show = false"
/>
export default {
  data() {
    return {
      show: false,
      value: '',
    };
  },
};

API

Props

Attribute Description Type Default
v-model (value) Current value string -
show Whether to show keyboard boolean -
title Keyboard title string -
theme Keyboard themecan be set to custom string default
maxlength Value maxlength number | string -
transition Whether to show transition animation boolean true
z-index Keyboard z-index number | string 100
extra-key v2.8.2 Content of bottom left key string | string[] ''
close-button-text Close button text string -
delete-button-text Delete button text string Delete Icon
close-button-loading v2.7.0 Whether to show loading close button in custom theme boolean false
show-delete-key v2.5.9 Whether to show delete button boolean true
hide-on-click-outside Whether to hide keyboard when click outside boolean true
teleport v2.10.0 Return the mount node for NumberKeyboard string | Element -
safe-area-inset-bottom Whether to enable bottom safe area adaptation boolean true

Events

Event Description Arguments
input Triggered when keydown key: Content of the key
delete Triggered when press delete key -
close Triggered when click close button -
blur Triggered when click close button or blur keyboard -
show Triggered when keyboard is fully displayed -
hide Triggered when keyboard is fully hidden -

Slots

Name Description
delete Custom delete key content
extra-key Custom extra key content
title-left Custom title left content