mirror of https://github.com/ElemeFE/element
parent
57f159cfb4
commit
afb6625d7c
|
@ -126,6 +126,7 @@ Additional `large` and `small` sizes of the input box are available
|
||||||
|size | size of the component | string | large/small| — |
|
|size | size of the component | string | large/small| — |
|
||||||
|disabled| whether the component is disabled | boolean | — | false |
|
|disabled| whether the component is disabled | boolean | — | false |
|
||||||
|controls| whether to enable the control buttons | boolean | — | true |
|
|controls| whether to enable the control buttons | boolean | — | true |
|
||||||
|
|debounce| debounce delay when typing, in millisecond | number | — | 300 |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,7 @@
|
||||||
| size | 计数器尺寸 | string | large, small | — |
|
| size | 计数器尺寸 | string | large, small | — |
|
||||||
| disabled | 是否禁用计数器 | boolean | — | false |
|
| disabled | 是否禁用计数器 | boolean | — | false |
|
||||||
| controls | 是否使用控制按钮 | boolean | — | true |
|
| controls | 是否使用控制按钮 | boolean | — | true |
|
||||||
|
| debounce | 输入时的去抖延迟,毫秒 | number | — | 300 |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
| 事件名称 | 说明 | 回调参数 |
|
| 事件名称 | 说明 | 回调参数 |
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue