Skip to content

Stepper

stepper

Rule

Basic Example

js
const rule = {
    type: 'stepper',
    title: 'Number Input',
    field: 'stepper',
    value: 6,
    props: {
        min: 5,
        max: 10
    }
}

Props Configuration Examples

Set Value Range

js
const rule = {
    type: 'stepper',
    title: 'Purchase Quantity',
    field: 'quantity',
    value: 1,
    props: {
        min: 1,
        max: 100,
        step: 1,
    }
}

Decimal Precision

js
const rule = {
    type: 'stepper',
    title: 'Discount Rate',
    field: 'discount',
    value: 0.9,
    props: {
        min: 0,
        max: 1,
        step: 0.1,
        decimalLength: 1,
    }
}

Disable Input Box

js
const rule = {
    type: 'stepper',
    title: 'Quantity',
    field: 'quantity',
    value: 1,
    props: {
        disableInput: true,
        min: 1,
    }
}

Rounded Style

js
const rule = {
    type: 'stepper',
    title: 'Quantity',
    field: 'quantity',
    value: 1,
    props: {
        theme: 'round',
        min: 1,
    }
}

Events Examples

Handle Value Changes

js
const rule = {
    type: 'stepper',
    title: 'Purchase Quantity',
    field: 'quantity',
    value: 1,
    props: {
        min: 1,
        max: 100,
    },
    on: {
        change: (value, detail) => {
            console.log('Value changed:', value, detail);
        },
        plus: () => {
            console.log('Plus button clicked');
        },
        minus: () => {
            console.log('Minus button clicked');
        },
        overlimit: () => {
            console.log('Limit exceeded');
        },
    },
}

Calculate Total Price After Value Changes

js
const rule = [
    {
        type: 'stepper',
        title: 'Unit Price',
        field: 'price',
        value: 0,
        props: {
            min: 0,
            step: 0.01,
            decimalLength: 2,
        },
        inject: true,
        on: {
            change: ($inject, value) => {
                // Auto-calculate total price
                const quantity = $inject.api.getValue('quantity') || 1;
                const total = value * quantity;
                $inject.api.setValue('total', total.toFixed(2));
            },
        },
    },
    {
        type: 'stepper',
        title: 'Quantity',
        field: 'quantity',
        value: 1,
        props: {
            min: 1,
        },
        inject: true,
        on: {
            change: ($inject, value) => {
                // Calculate total price
                const price = $inject.api.getValue('price') || 0;
                const total = price * value;
                $inject.api.setValue('total', total.toFixed(2));
            },
        },
    },
    {
        type: 'stepper',
        title: 'Total Price',
        field: 'total',
        props: {
            disabled: true,
            decimalLength: 2,
        },
    },
]

Complete configuration items:Vant_Stepper

value :Number

Props

ParameterDescriptionTypeDefault Value
minMinimum valuenumber | string1
maxMaximum valuenumber | string-
auto-fixedWhether to automatically correct values that exceed the limit range, set to false to prevent automatic correctionbooleantrue
default-valueInitial value, takes effect when v-model is emptynumber | string1
stepStep size, value changed each time when clickednumber | string1
nameIdentifier, usually a unique string or number, can be obtained in the change event callback parametersnumber | string-
input-widthInput box width, default unit is pxnumber | string32px
button-sizeButton size and input box height, default unit is pxnumber | string28px
decimal-lengthFixed number of decimal places to displaynumber | string-
themeStyle theme, optional value is roundstring-
placeholderInput box placeholder textstring-
integerWhether to only allow integer inputbooleanfalse
disabledWhether to disable stepperbooleanfalse
disable-plusWhether to disable plus buttonbooleanfalse
disable-minusWhether to disable minus buttonbooleanfalse
disable-inputWhether to disable input boxbooleanfalse
before-changeCallback function before input value changes, return false to prevent input, supports returning Promise(value: number | string) => boolean | Promise<boolean>false
show-plusWhether to show plus buttonbooleantrue
show-minusWhether to show minus buttonbooleantrue
show-inputWhether to show input boxbooleantrue
long-pressWhether to enable long press gesture, enables long press on plus and minus buttons when enabledbooleantrue
allow-emptyWhether to allow empty input value, set to true to allow empty stringbooleanfalse

Events

Event NameDescriptionCallback Parameters
changeEvent triggered when bound value changesvalue: string, detail: { name: string }
overlimitTriggered when unavailable button is clicked-
plusTriggered when plus button is clicked-
minusTriggered when minus button is clicked-
focusTriggered when input box gains focusevent: Event
blurTriggered when input box loses focusevent: Event

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.