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() {
|
||||
let value = this.value ? +this.value : +this.defaultValue;
|
||||
const correctedValue = this.correctValue(value);
|
||||
if (value !== correctedValue) {
|
||||
value = correctedValue;
|
||||
this.$emit('input', value);
|
||||
}
|
||||
return {
|
||||
currentValue: this.value ? +this.value : +this.defaultValue
|
||||
currentValue: value
|
||||
};
|
||||
},
|
||||
|
||||
@ -66,38 +72,37 @@ export default {
|
||||
|
||||
watch: {
|
||||
currentValue(val) {
|
||||
this.$emit('input', +val);
|
||||
this.$emit('input', val);
|
||||
this.$emit('change', val);
|
||||
},
|
||||
value(val) {
|
||||
if (val) {
|
||||
this.currentValue = +val;
|
||||
this.currentValue = this.correctValue(+val);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
// 纠正value值
|
||||
correctValue(value) {
|
||||
value = Math.max(this.min, value);
|
||||
value = Math.min(this.max, value);
|
||||
return value;
|
||||
},
|
||||
handleInputChange(event) {
|
||||
let val = +event.target.value;
|
||||
const max = +this.max;
|
||||
const min = +this.min;
|
||||
const val = +event.target.value;
|
||||
|
||||
if (val > max) {
|
||||
val = max;
|
||||
} else if (val < min) {
|
||||
val = min;
|
||||
}
|
||||
|
||||
this.currentValue = val;
|
||||
this.currentValue = this.correctValue(val);
|
||||
},
|
||||
handleChange(type) {
|
||||
if ((this.isMinusDisabled && type === 'minus') || (this.isPlusDisabled && type === 'plus')) {
|
||||
this.$emit('overlimit', type);
|
||||
return;
|
||||
}
|
||||
|
||||
const step = +this.step;
|
||||
const currentValue = +this.currentValue;
|
||||
this.currentValue = type === 'minus' ? (currentValue - step) : (currentValue + step);
|
||||
this.$emit('change', this.currentValue);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user