Skip to content

NumberInput 数字输入

专用于输入数字。每个输入框只允许输入一个字符,主要用于验证码、密码输入框等。

导入

js
import NumberInput from '@/components/form/NumberInput.vue';

使用方法

基础用法

最简单的使用方式,默认显示6位数字输入框。

vue
<template>
  <NumberInput v-model="value1" />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import NumberInput from '@/components/form/NumberInput.vue';

const value1 = ref('');
</script>

使用 NumberKeyBoard 输入键盘

不使用系统键盘,使用内置的 NumberKeyBoard 键盘。

vue
<template>
  <NumberInput v-model="value6" :useSystemInput="false" />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import NumberInput from '@/components/form/NumberInput.vue';

const value6 = ref('');
</script>

自定义长度

设置自定义的数字位数。

vue
<template>
  <NumberInput 
    v-model="value2"
    :numberCount="8"
    :boxStyle="{
      paddingHorizontal: 0,
    }"
    autoSize 
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import NumberInput from '@/components/form/NumberInput.vue';

const value2 = ref('');
</script>

格子间距

设置输入框格子之间的间距。

vue
<template>
  <NumberInput v-model="value3" :numberCount="4" :gutter="20" autoSize />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import NumberInput from '@/components/form/NumberInput.vue';

const value3 = ref('');
</script>

下划线边框

使用下划线样式的边框。

vue
<template>
  <NumberInput
    v-model="value4"
    :numberCount="4"
    :borderWidth="4"
    borderColor="border.default"
    borderType="underline"
    activeBorderColor="primary"
    :gutter="10"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import NumberInput from '@/components/form/NumberInput.vue';

const value4 = ref('');
</script>

密码输入

设置为密码输入模式,显示为圆点。

vue
<template>
  <NumberInput v-model="value5" isPassword info="密码为 6 位数字" />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import NumberInput from '@/components/form/NumberInput.vue';

const value5 = ref('');
</script>

API 参考

Props

名称说明类型必填默认值
modelValue数值string-
errorMessage底部错误提示文案,为空时不展示string-
numberCount数字位数number6
isPassword是否是密码booleanfalse
startFocus是否在组件初始化时激活键盘booleanfalse
useSystemInput使用系统输入键盘,否则使用 NumberKeyBoard 作为输入键盘booleantrue
info输入框下方文字提示string-
gutter输入框格子之间的间距number4
autoSize是否自动调整宽度booleanfalse
borderType格子的边框样式'underline' | 'box''box'
borderColor格子的边框颜色string'border.default'
borderWidth格子的边框宽度number4
activeBorderColor已输入格子的边框颜色string'primary'
boxStyle格子样式ViewStyle-
disableKeyPad是否禁用点击打开键盘booleanfalse
showCursur是否显示输入闪烁光标booleantrue
finishHideKeyPad是否在输入完成后自动收起键盘booleantrue
textStyle文字样式TextStyle-
innerStyle外层样式ViewStyle-

Events

名称说明参数
update:modelValue文字更改回调string
enterFinish当输入完成(全部位数都已经输入)时返回事件string

主题变量

变量名类型默认值说明
NumberInputBorderTypestring'box'默认边框类型
NumberInputBorderWidthnumber4默认边框宽度
NumberInputGutternumber4默认格子间距
NumberInputBorderColorstring'border.default'默认边框颜色
NumberInputActiveBorderColorstring'primary'已输入格子的边框颜色
NumberInputInfoMarginTopnumber10提示文字上边距
NumberInputInfoColorstring'text.second'提示文字颜色
NumberInputErrorMessageMarginTopnumber10错误提示文字上边距
NumberInputErrorMessageColorstring'danger'错误提示文字颜色