|
@@ -27,7 +27,7 @@
|
|
@keydown.up.native.prevent="increase"
|
|
@keydown.up.native.prevent="increase"
|
|
@keydown.down.native.prevent="decrease"
|
|
@keydown.down.native.prevent="decrease"
|
|
@blur="handleBlur"
|
|
@blur="handleBlur"
|
|
- @input="handleInput"
|
|
|
|
|
|
+ @input="debounceHandleInput"
|
|
:disabled="disabled"
|
|
:disabled="disabled"
|
|
:size="size"
|
|
:size="size"
|
|
:max="max"
|
|
:max="max"
|
|
@@ -46,6 +46,7 @@
|
|
<script>
|
|
<script>
|
|
import ElInput from 'element-ui/packages/input';
|
|
import ElInput from 'element-ui/packages/input';
|
|
import { once, on } from 'element-ui/src/utils/dom';
|
|
import { once, on } from 'element-ui/src/utils/dom';
|
|
|
|
+ import debounce from 'throttle-debounce/debounce';
|
|
|
|
|
|
export default {
|
|
export default {
|
|
name: 'ElInputNumber',
|
|
name: 'ElInputNumber',
|
|
@@ -96,6 +97,10 @@
|
|
controls: {
|
|
controls: {
|
|
type: Boolean,
|
|
type: Boolean,
|
|
default: true
|
|
default: true
|
|
|
|
+ },
|
|
|
|
+ debounce: {
|
|
|
|
+ type: Number,
|
|
|
|
+ default: 300
|
|
}
|
|
}
|
|
},
|
|
},
|
|
data() {
|
|
data() {
|
|
@@ -177,17 +182,30 @@
|
|
const oldVal = this.currentValue;
|
|
const oldVal = this.currentValue;
|
|
if (newVal >= this.max) newVal = this.max;
|
|
if (newVal >= this.max) newVal = this.max;
|
|
if (newVal <= this.min) newVal = this.min;
|
|
if (newVal <= this.min) newVal = this.min;
|
|
- if (oldVal === newVal) return;
|
|
|
|
|
|
+ if (oldVal === newVal) {
|
|
|
|
+ this.$refs.input.setCurrentValue(this.currentValue);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
this.$emit('change', newVal, oldVal);
|
|
this.$emit('change', newVal, oldVal);
|
|
this.$emit('input', newVal);
|
|
this.$emit('input', newVal);
|
|
this.currentValue = newVal;
|
|
this.currentValue = newVal;
|
|
},
|
|
},
|
|
handleInput(value) {
|
|
handleInput(value) {
|
|
|
|
+ if (value === '') {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
const newVal = Number(value);
|
|
const newVal = Number(value);
|
|
if (!isNaN(newVal)) {
|
|
if (!isNaN(newVal)) {
|
|
this.setCurrentValue(newVal);
|
|
this.setCurrentValue(newVal);
|
|
|
|
+ } else {
|
|
|
|
+ this.$refs.input.setCurrentValue(this.currentValue);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ },
|
|
|
|
+ created() {
|
|
|
|
+ this.debounceHandleInput = debounce(this.debounce, value => {
|
|
|
|
+ this.handleInput(value);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
};
|
|
};
|
|
</script>
|
|
</script>
|