增加修正quantity值的方法

This commit is contained in:
niunai 2017-03-26 15:22:11 +08:00
parent 09b4686860
commit 28dfee7429

View File

@ -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);
}
}
};