2020-08-13 15:18:26 +08:00
## InputNumber
Input numerical values with a customizable range.
### Basic usage
:::demo Bind a variable to `v-model` in `<el-input-number>` element and you are set.
```html
< template >
2021-09-04 19:29:28 +08:00
< el-input-number
v-model="num"
@change ="handleChange"
:min="1"
:max="10"
>< / el-input-number >
2020-08-13 15:18:26 +08:00
< / template >
< script >
export default {
data() {
return {
2021-09-04 19:29:28 +08:00
num: 1,
}
2020-08-13 15:18:26 +08:00
},
methods: {
handleChange(value) {
2021-09-04 19:29:28 +08:00
console.log(value)
},
},
}
2020-08-13 15:18:26 +08:00
< / script >
2021-06-10 00:21:18 +08:00
<!--
< setup >
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const num = ref(1);
const handleChange = (value) => {
console.log(value);
};
return {
num,
handleChange,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Disabled
:::demo The `disabled` attribute accepts a `boolean` , and if the value is `true` , the component is disabled. If you just need to control the value within a range, you can add `min` attribute to set the minimum value and `max` to set the maximum value. By default, the minimum value is `0` .
```html
< template >
< el-input-number v-model = "num" :disabled = "true" > < / el-input-number >
< / template >
< script >
export default {
data() {
return {
2021-09-04 19:29:28 +08:00
num: 1,
2020-08-13 15:18:26 +08:00
}
2021-09-04 19:29:28 +08:00
},
}
2020-08-13 15:18:26 +08:00
< / script >
2021-06-10 00:21:18 +08:00
<!--
< setup >
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const num = ref(1);
return {
num,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Steps
Allows you to define incremental steps.
:::demo Add `step` attribute to set the step.
```html
< template >
< el-input-number v-model = "num" :step = "2" > < / el-input-number >
< / template >
< script >
export default {
data() {
return {
2021-09-04 19:29:28 +08:00
num: 5,
2020-08-13 15:18:26 +08:00
}
2021-09-04 19:29:28 +08:00
},
}
2020-08-13 15:18:26 +08:00
< / script >
2021-06-10 00:21:18 +08:00
<!--
< setup >
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const num = ref(5);
return {
num,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Step strictly
:::demo The `step-strictly` attribute accepts a `boolean` . if this attribute is `true` , input value can only be multiple of step.
```html
< template >
< el-input-number v-model = "num" :step = "2" step-strictly > < / el-input-number >
< / template >
< script >
export default {
data() {
return {
2021-09-04 19:29:28 +08:00
num: 2,
2020-08-13 15:18:26 +08:00
}
2021-09-04 19:29:28 +08:00
},
}
2020-08-13 15:18:26 +08:00
< / script >
2021-06-10 00:21:18 +08:00
<!--
< setup >
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const num = ref(2);
return {
num,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Precision
:::demo Add `precision` attribute to set the precision of input value.
```html
< template >
2021-09-04 19:29:28 +08:00
< el-input-number
v-model="num"
:precision="2"
:step="0.1"
:max="10"
>< / el-input-number >
2020-08-13 15:18:26 +08:00
< / template >
< script >
export default {
data() {
return {
2021-09-04 19:29:28 +08:00
num: 1,
2020-08-13 15:18:26 +08:00
}
2021-09-04 19:29:28 +08:00
},
}
2020-08-13 15:18:26 +08:00
< / script >
2021-06-10 00:21:18 +08:00
<!--
< setup >
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const num = ref(1);
return {
num,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
:::
:::tip
The value of `precision` must be a non negative integer and should not be less than the decimal places of `step` .
:::
### Size
Use attribute `size` to set additional sizes with `medium` , `small` or `mini` .
:::demo
```html
< template >
< el-input-number v-model = "num1" > < / el-input-number >
2021-09-04 19:29:28 +08:00
< el-input-number size = "medium" v-model = "num2" > < / el-input-number >
< el-input-number size = "small" v-model = "num3" > < / el-input-number >
< el-input-number size = "mini" v-model = "num4" > < / el-input-number >
2020-08-13 15:18:26 +08:00
< / template >
< script >
export default {
data() {
return {
num1: 1,
num2: 1,
num3: 1,
2021-09-04 19:29:28 +08:00
num4: 1,
2020-08-13 15:18:26 +08:00
}
2021-09-04 19:29:28 +08:00
},
}
2020-08-13 15:18:26 +08:00
< / script >
2021-06-10 00:21:18 +08:00
<!--
< setup >
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const num1 = ref(1);
const num2 = ref(2);
const num3 = ref(3);
const num4 = ref(4);
return {
num1,
num2,
num3,
num4,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Controls Position
:::demo Set `controls-position` to decide the position of control buttons.
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
```html
< template >
2021-09-04 19:29:28 +08:00
< el-input-number
v-model="num"
controls-position="right"
@change ="handleChange"
:min="1"
:max="10"
>< / el-input-number >
2020-08-13 15:18:26 +08:00
< / template >
< script >
export default {
data() {
return {
2021-09-04 19:29:28 +08:00
num: 1,
}
2020-08-13 15:18:26 +08:00
},
methods: {
handleChange(value) {
2021-09-04 19:29:28 +08:00
console.log(value)
},
},
}
2020-08-13 15:18:26 +08:00
< / script >
2021-06-10 00:21:18 +08:00
<!--
< setup >
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const num = ref(1);
const handleChange = (value) => {
console.log(value);
};
return {
num,
handleChange,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Attributes
2021-09-04 19:29:28 +08:00
| Attribute | Description | Type | Accepted Values | Default |
| --------------------- | ------------------------------------------------ | ------------------ | ----------------------- | ----------- |
| model-value / v-model | binding value | number / undefined | — | 0 |
| min | the minimum allowed value | number | — | `-Infinity` |
| max | the maximum allowed value | number | — | `Infinity` |
| step | incremental step | number | — | 1 |
| step-strictly | whether input value can only be multiple of step | boolean | — | false |
| precision | precision of input value | number | — | — |
| size | size of the component | string | large/medium/small/mini | large |
| disabled | whether the component is disabled | boolean | — | false |
| controls | whether to enable the control buttons | boolean | — | true |
| controls-position | position of the control buttons | string | right | - |
| name | same as `name` in native input | string | — | — |
| label | label text | string | — | — |
| placeholder | placeholder in input | string | - | - |
2020-08-13 15:18:26 +08:00
### Events
2021-09-04 19:29:28 +08:00
| Event Name | Description | Parameters |
| ---------- | ------------------------------- | ---------------------- |
| change | triggers when the value changes | currentValue, oldValue |
| blur | triggers when Input blurs | (event: Event) |
| focus | triggers when Input focuses | (event: Event) |
2020-08-13 15:18:26 +08:00
### Methods
2021-09-04 19:29:28 +08:00
| Method | Description | Parameters |
| ------ | -------------------------------- | ---------- |
| focus | focus the Input component | - |
| select | select the text in input element | — |