Skip to content

NumberBox

This component is used to control numerical increments and decrements through plus and minus buttons, commonly used for shopping cart quantity selection, quantity adjustment, and similar scenarios.

  • Supports setting minimum and maximum value limits
  • Supports setting step size and decimal places
  • Supports disabling direct input editing
  • Supports individually disabling plus and minus buttons
  • Provides method invocation capabilities (getValue, plus, minus)

Notice

This component may have slight differences in appearance across platforms. Please refer to the actual effect.

Platform Differences

App (vue)App (nvue)H5Mini Program

Basic Usage

  • Bind the value via v-model, default value is 0.
  • Set the value range via min and max.
html
<see-number-box v-model="value" />

<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(1);
</script>

Step Size

  • Set the change amount for each click of the plus or minus button via step, default is 1.
html
<see-number-box v-model="value" :step="5" />

<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(10);
</script>

Decimal Places

  • Set the number of decimal places to retain via decimalLength.
html
<see-number-box v-model="value" :step="0.1" :decimalLength="1" />

<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(1.0);
</script>

Range Limits

  • Set the minimum value via min, default is 0.
  • Set the maximum value via max, default is Infinity.
html
<see-number-box v-model="value" :min="1" :max="10" />

<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(5);
</script>

Disabled Input

  • Set isDisabledInput to true to prohibit direct editing of the input box, only allowing operation through plus and minus buttons.
html
<see-number-box v-model="value" isDisabledInput />

<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(1);
</script>

Disabled Plus/Minus Buttons

  • Set isDisabledPlus to true to disable the plus button.
  • Set isDisabledMinus to true to disable the minus button.
html
<see-number-box v-model="value" isDisabledPlus />
<see-number-box v-model="value" isDisabledMinus />

<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(1);
</script>

Disabled State

  • Set isDisabled to true to disable the entire number box.
  • In disabled state, all operations are unavailable.
html
<see-number-box v-model="value" isDisabled />

<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(1);
</script>

Readonly State

  • Set isReadonly to true to set the number box to readonly state.
  • In readonly state, operations will not trigger, but the style remains unchanged.
html
<see-number-box v-model="value" isReadonly />

<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(1);
</script>

Different Sizes

  • Set the number box size via the size parameter. Available values are small, default, and large.
html
<see-number-box v-model="value" size="small" />
<see-number-box v-model="value" size="default" />
<see-number-box v-model="value" size="large" />

<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(1);
</script>

Async Change

  • Set isAsync to true to enable async change mode.
  • In async mode, the value will not update automatically and needs to be manually updated via v-model. This is suitable for scenarios requiring async validation in onChange.
html
<see-number-box v-model="value" isAsync @onChange="onChange" />

<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(1);

const onChange = (val: number) => {
  // Manually update after async validation passes
  value.value = val;
};
</script>

API

Props

ParameterDescriptionTypeDefaultOptional ValuesPlatform Notes
modelValueBinding valuenumber0--
minMinimum valuenumber0--
maxMaximum valuenumberInfinity--
stepStep sizenumber1Any positive number-
isDisabledWhether disabledbooleanfalsetrue, false-
isReadonlyWhether readonlybooleanfalsetrue, false-
isDisabledInputWhether to disable inputbooleanfalsetrue, false-
isDisabledPlusWhether to disable plus buttonbooleanfalsetrue, false-
isDisabledMinusWhether to disable minus buttonbooleanfalsetrue, false-
decimalLengthDecimal placesnumber-Any non-negative integer-
sizeSize"small" | "default" | "large"'default'small, default, large-
inputWidthInput width (px)number60Any positive number-
isAsyncWhether it is async change modebooleanfalsetrue, false-
nameForm field namestring''--

Events

Event NameDescriptionCallback Parameters
onChangeTriggered when value changesvalue: Current value
onOverlimitTriggered when value exceeds range limitsvalue: Current value
onPlusTriggered when plus button is clickedvalue: Current value
onMinusTriggered when minus button is clickedvalue: Current value
onFocusTriggered when input gains focusevent: Focus event object
onBlurTriggered when input loses focusevent: Focus event object

Methods

Call after obtaining the component instance via ref.

Method NameDescriptionParametersReturn Value
getValueGet current value-number
plusExecute plus operation--
minusExecute minus operation--

Liao ICP No. 2025070134