May 07, 2021 Vant
The stepr consists of an add button, a reduction button, and an input box to enter and adjust numbers within a certain range
import Vue from 'vue';
import { Stepper } from 'vant';
Vue.use(Stepper);
By binding the input value with v-model, you can listen for changes in the input value through the change event
<van-stepper v-model="value" />
export default {
data() {
return {
value: 1
}
}
}
Use the step property to set the value that changes each time you click the Add or Decrease button, which defaults to 1
<van-stepper v-model="value" step="2" />
Limit the range of input values with min and max properties
<van-stepper v-model="value" min="5" max="8" />
When the integer property is set, the input box limits that only integers can be entered
<van-stepper v-model="value" integer />
You can't click a button or modify the input box by setting the disabled property to disable the stepr
<van-stepper v-model="value" disabled />
The input box is disabled by setting the disabled-input property, at which point the button can still be clicked
<van-stepper v-model="value" disabled-input />
You can keep a fixed scale by setting the decimal-length property
<van-stepper v-model="value" step="0.2" :decimal-length="1" />
Set the width of the input box with the input-width property, and set the button size and input box height with the button-size property
<van-stepper v-model="value" input-width="40px" button-size="32px" />
If you need to modify the value of the input box asynchronously, you can set the async-change property and manually modify the value in the change event
<van-stepper
:value="value"
async-change
@change="onChange"
/>
import { Toast } from 'vant';
export default {
data() {
return {
value: 1
}
},
methods: {
onChange(value) {
Toast.loading({ forbidClick: true });
setTimeout(() => {
Toast.clear();
// 注意此时修改 value 后会再次触发 change 事件
this.value = value;
}, 500);
}
}
}
Parameters | Description | Type | The default |
---|---|---|---|
v-model | The current input value | number | string | - |
min | The minimum value | number | string |
1
|
max | The maximum value | number | string | - |
default-value | Initial value, effective when v-model is empty | number | string |
1
|
step | Step, the value that changes each time you click | number | string |
1
|
name
v2.2.11
|
Identifier, which can be
change
in the change event callback parameter
|
number | string | - |
input-width |
Enter the box width in
px
|
number | string |
32px
|
button-size
v2.0.5
|
The button size and input box height, the default unit
px
|
number | string |
28px
|
decimal-length
v2.2.1
|
Pin the number of scales displayed | number | string | - |
integer | Whether only integers are allowed to be entered | boolean |
false
|
disabled | Whether to disable the stepr | boolean |
false
|
disable-plus
v2.2.16
|
Whether to disable the add button | boolean |
false
|
disable-minus
v2.2.16
|
Whether to disable the reduction button | boolean |
false
|
disable-input | Whether to disable the input box | boolean |
false
|
async-change | Whether to turn on asynchronous changes, manual control of input values is required after opening | boolean |
false
|
show-plus
v2.1.2
|
Whether to display the add button | boolean |
true
|
show-minus
v2.1.2
|
Whether to display the reduction button | boolean |
true
|
long-press
v2.4.3
|
Whether to turn on the long-press gesture | boolean |
true
|
The name of the event | Description | Callback parameters |
---|---|---|
change | The event that is triggered when the binding value changes | value: The value of the current component, detail: additional information, containing the field name |
overlimit | Triggered when an unavailable button is clicked | - |
plus | Triggered when the add button is clicked | - |
minus | Triggered when the reduction button is clicked | - |
focus | Triggered when the input box is focused | event: Event |
blur | Triggered when the input box loses focus | event: Event |