Number Input 数字输入框

用于输入数字的专用输入框组件

<script setup lang="ts">
import { ref } from 'vue'

const value = ref(0)
</script>

<template>
  <div class="flex justify-center p-4 w-full">
    <SkNumberInput v-model="value" placeholder="请输入数字" />
  </div>
</template>

用法

Controlled 数值

Prop类型默认值描述
v-modelnumber-设置数字输入框的值 (双向绑定)
<script setup lang="ts">
import { ref } from 'vue'

const value = ref(0)
</script>

<template>
  <div class="flex justify-center p-4 w-full">
    <SkNumberInput v-model="value" placeholder="请输入数字" />
  </div>
</template>

Placeholder 占位符

Prop类型默认值描述
placeholderstring-设置数字输入框占位符文本
<script setup lang="ts">
import { ref } from 'vue'

const value = ref()
</script>

<template>
  <div class="flex flex-col gap-3 p-4">
    <SkNumberInput v-model="value" placeholder="请输入数字" />
  </div>
</template>

Min/Max 最小值/最大值

Prop类型默认值描述
minnumber-设置数字输入框最小值
maxnumber-设置数字输入框最大值
<script setup lang="ts">
import { ref } from 'vue'

const value1 = ref(0)
const value2 = ref(100)
</script>

<template>
  <div class="flex flex-col p-4 gap-3">
    <SkNumberInput v-model="value1" :min="0" :max="10" placeholder="范围 0-10" />
    <SkNumberInput v-model="value2" :min="10" :max="100" placeholder="范围 10-100" />
  </div>
</template>

Step 步长

Prop类型默认值描述
stepnumber1设置数字输入框步长
<script setup lang="ts">
import { ref } from 'vue'

const value1 = ref(0)
const value2 = ref(0)
</script>

<template>
  <div class="flex flex-col p-4 gap-3">
    <SkNumberInput v-model="value1" :step="5" placeholder="步长 5" />
    <SkNumberInput v-model="value2" :step="0.1" placeholder="步长 0.1" />
  </div>
</template>

StepStrictly 严格步长

Prop类型默认值描述
stepStrictlybooleanfalse设置数字输入框是否严格步长(值必须是步长的倍数)
<script setup lang="ts">
import { ref } from 'vue'

const normalValue = ref(7)
const strictValue = ref(10)
</script>

<template>
  <div class="flex flex-col p-4 gap-3">
    <SkNumberInput v-model="normalValue" :step="5" placeholder="普通步长模式" />
    <SkNumberInput v-model="strictValue" :step="5" step-strictly placeholder="严格步长模式" />
  </div>
</template>

Size 尺寸

Prop类型默认值描述
size{Size}medium设置数字输入框的尺寸大小
Size描述
small小型
medium中型
large大型
<script setup lang="ts">
import { ref } from 'vue'

const smallValue = ref(0)
const mediumValue = ref(0)
const largeValue = ref(0)
</script>

<template>
  <div class="flex flex-col items-center p-4 gap-3">
    <SkNumberInput v-model="smallValue" size="small" placeholder="小尺寸" />
    <SkNumberInput v-model="mediumValue" size="medium" placeholder="中尺寸" />
    <SkNumberInput v-model="largeValue" size="large" placeholder="大尺寸" />
  </div>
</template>

Disabled 禁用

Prop类型默认值描述
disabledbooleanfalse设置数字输入框是否为禁用状态
<script setup lang="ts">
import { ref } from 'vue'

const normalValue = ref(10)
const disabledValue = ref(20)
</script>

<template>
  <div class="flex flex-col p-4 gap-3 w-full">
    <SkNumberInput v-model="normalValue" placeholder="正常状态" />
    <SkNumberInput v-model="disabledValue" disabled placeholder="禁用状态" />
  </div>
</template>

Readonly 只读

Prop类型默认值描述
readonlybooleanfalse设置数字输入框是否为只读状态
<script setup lang="ts">
import { ref } from 'vue'

const normalValue = ref(10)
const readonlyValue = ref(20)
</script>

<template>
  <div class="flex flex-col p-4 gap-3 w-full">
    <SkNumberInput v-model="normalValue" placeholder="正常状态" />
    <SkNumberInput v-model="readonlyValue" readonly placeholder="只读状态" />
  </div>
</template>

FormatOptions 格式化选项

该属性目前处于实验性阶段,需要更加完备的测试,欢迎试用并提供反馈
Prop类型默认值描述
formatOptionsIntl.NumberFormatOptions-设置数字输入框格式化选项
<script setup lang="ts">
import { ref } from 'vue'

const currencyValue = ref(1000)
</script>

<template>
  <div class="flex flex-col p-4 gap-3 w-full">
    <SkNumberInput
      v-model="currencyValue"
      :format-options="{ style: 'currency', currency: 'CNY' }"
      placeholder="货币格式"
    />
  </div>
</template>

接口

Props

属性名类型默认值描述
v-modelnumber-详见 Controlled 数值
placeholderstring-详见 Placeholder 占位符
size{Size}'medium'详见 Size 尺寸
minnumber-详见 Min/Max 最小值/最大值
maxnumber-详见 Min/Max 最小值/最大值
stepnumber1详见 Step 步长
stepStrictlybooleanfalse详见 StepStrictly 严格步长
disabledbooleanfalse详见 Disabled 禁用
readonlybooleanfalse详见 Readonly 只读
formatOptionsIntl.NumberFormatOptions-详见 FormatOptions 格式化选项

Emits

事件名参数描述
change(value: number)当输入框数值改变时触发
focus(event: Event)当输入框获得焦点时触发
blur(event: Event)当输入框失去焦点时触发

交互

正在完善中,敬请期待!😊