Skip to content

Stepper - Vant 4

Stepper

Intro

The stepper component consists of an increase button, a decrease button and an input box, which are used to input and adjust numbers within a certain range.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

js
import { createApp } from'vue'; import { Stepper } from'vant'; const app = createApp(); app.use(Stepper);

Usage

Basic Usage

html
js
import { ref } from'vue'; exportdefault { setup() { const value = ref(1); return { value }; }, };

Step

html

Range

html

Integer

html

Disabled

html

Disable Input

html

Decimal Length

html

Custom Size

html

Before Change

html
js
import { ref } from'vue'; import { closeToast, showLoadingToast } from'vant'; exportdefault { setup() { const value = ref(1); constbeforeChange = (value) => { showLoadingToast({ forbidClick: true }); returnnewPromise((resolve) => { setTimeout(() => { closeToast(); // resolve 'true' or 'false'resolve(true); }, 500); }); }; return { value, beforeChange, }; }, };

Round Theme

html

API

Props

AttributeDescriptionTypeDefault
v-modelCurrent value*numberstring*
minMin value*numberstring*
maxMax value*numberstring*
auto-fixedWhether to auto fix value that is out of range, set to false and value that is out of range won��t be auto fixedbooleantrue
default-valueDefault value, valid when v-model is empty*numberstring*
stepValue change step*numberstring*
nameStepper name, usually a unique string or number*numberstring*
input-widthInput width*numberstring*
button-sizeButton size*numberstring*
decimal-lengthDecimal length*numberstring*
themeTheme, can be set to roundstring-
placeholderInput placeholderstring-
integerWhether to allow only integersbooleanfalse
disabledWhether to disable value changebooleanfalse
disable-plusWhether to disable plus buttonbooleanfalse
disable-minusWhether to disable minus buttonbooleanfalse
disable-inputWhether to disable inputbooleanfalse
before-changeCallback function before changing, return false to prevent change, support return Promise*(value: numberstring) => boolean
show-plusWhether to show plus buttonbooleantrue
show-minusWhether to show minus buttonbooleantrue
show-inputWhether to show inputbooleantrue
long-pressWhether to enable the long press gesture, when enabled you can long press the increase and decrease buttonsbooleantrue
allow-emptyWhether to allow the input value to be empty, set to true to allow an empty string to be passed inbooleanfalse

Events

EventDescriptionArguments
changeEmitted when value changedvalue: string, detail: { name: string }
overlimitEmitted when a disabled button is clicked-
plusEmitted when the plus button is clicked-
minusEmitted when the minus button is clicked-
focusEmitted when the input is focusedevent: Event
blurEmitted when the input is blurredevent: Event

Types

The component exports the following type definitions:

ts
importtype { StepperTheme, StepperProps } from'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-stepper-backgroundvar(--van-active-color)-
--van-stepper-button-icon-colorvar(--van-text-color)-
--van-stepper-button-disabled-colorvar(--van-background)-
--van-stepper-button-disabled-icon-colorvar(--van-gray-5)-
--van-stepper-button-round-theme-colorvar(--van-primary-color)-
--van-stepper-input-width32px-
--van-stepper-input-height28px-
--van-stepper-input-font-sizevar(--van-font-size-md)-
--van-stepper-input-line-heightnormal-
--van-stepper-input-text-colorvar(--van-text-color)-
--van-stepper-input-disabled-text-colorvar(--van-text-color-3)-
--van-stepper-input-disabled-backgroundvar(--van-active-color)-
--van-stepper-radiusvar(--van-radius-md)-

Enterprise-level mobile solution based on Vant