mirror of
https://github.com/youzan/vant.git
synced 2025-10-18 09:24:25 +00:00
[Improvement] Stepper: add interger prop (#951)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
:value="currentValue"
|
||||
:disabled="disabled || disableInput"
|
||||
@input="onInput"
|
||||
@keypress="onKeypress"
|
||||
>
|
||||
<button
|
||||
:class="b('plus', { disabled: plusDisabled })"
|
||||
@@ -26,6 +27,7 @@ export default create({
|
||||
|
||||
props: {
|
||||
value: {},
|
||||
interger: Boolean,
|
||||
disabled: Boolean,
|
||||
disableInput: Boolean,
|
||||
min: {
|
||||
@@ -88,14 +90,9 @@ export default create({
|
||||
|
||||
methods: {
|
||||
correctValue(value) {
|
||||
if (Number.isNaN(value)) {
|
||||
value = this.min;
|
||||
} else {
|
||||
value = Math.max(this.min, value);
|
||||
value = Math.min(this.max, value);
|
||||
}
|
||||
|
||||
return value;
|
||||
return Number.isNaN(value)
|
||||
? this.min
|
||||
: Math.max(this.min, Math.min(this.max, value));
|
||||
},
|
||||
|
||||
onInput(event) {
|
||||
@@ -118,6 +115,12 @@ export default create({
|
||||
this.$emit(type);
|
||||
},
|
||||
|
||||
onKeypress(event) {
|
||||
if (this.interger && event.keyCode === 46) {
|
||||
event.preventDefault();
|
||||
}
|
||||
},
|
||||
|
||||
emitInput() {
|
||||
this.$emit('input', this.currentValue);
|
||||
this.$emit('change', this.currentValue);
|
||||
|
Reference in New Issue
Block a user