mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
增加修正quantity值的方法
This commit is contained in:
parent
09b4686860
commit
28dfee7429
@ -44,8 +44,14 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
|
let value = this.value ? +this.value : +this.defaultValue;
|
||||||
|
const correctedValue = this.correctValue(value);
|
||||||
|
if (value !== correctedValue) {
|
||||||
|
value = correctedValue;
|
||||||
|
this.$emit('input', value);
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
currentValue: this.value ? +this.value : +this.defaultValue
|
currentValue: value
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -66,38 +72,37 @@ export default {
|
|||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
currentValue(val) {
|
currentValue(val) {
|
||||||
this.$emit('input', +val);
|
this.$emit('input', val);
|
||||||
|
this.$emit('change', val);
|
||||||
},
|
},
|
||||||
value(val) {
|
value(val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
this.currentValue = +val;
|
this.currentValue = this.correctValue(+val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
// 纠正value值
|
||||||
|
correctValue(value) {
|
||||||
|
value = Math.max(this.min, value);
|
||||||
|
value = Math.min(this.max, value);
|
||||||
|
return value;
|
||||||
|
},
|
||||||
handleInputChange(event) {
|
handleInputChange(event) {
|
||||||
let val = +event.target.value;
|
const val = +event.target.value;
|
||||||
const max = +this.max;
|
|
||||||
const min = +this.min;
|
|
||||||
|
|
||||||
if (val > max) {
|
this.currentValue = this.correctValue(val);
|
||||||
val = max;
|
|
||||||
} else if (val < min) {
|
|
||||||
val = min;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.currentValue = val;
|
|
||||||
},
|
},
|
||||||
handleChange(type) {
|
handleChange(type) {
|
||||||
if ((this.isMinusDisabled && type === 'minus') || (this.isPlusDisabled && type === 'plus')) {
|
if ((this.isMinusDisabled && type === 'minus') || (this.isPlusDisabled && type === 'plus')) {
|
||||||
|
this.$emit('overlimit', type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const step = +this.step;
|
const step = +this.step;
|
||||||
const currentValue = +this.currentValue;
|
const currentValue = +this.currentValue;
|
||||||
this.currentValue = type === 'minus' ? (currentValue - step) : (currentValue + step);
|
this.currentValue = type === 'minus' ? (currentValue - step) : (currentValue + step);
|
||||||
this.$emit('change', this.currentValue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user