2016-11-10 21:46:55 +08:00
< script >
export default {
data() {
return {
num1: 1,
num2: 1,
2017-01-16 10:42:32 +08:00
num3: 5,
num4: 1,
num5: 1,
2017-10-18 18:31:03 +08:00
num6: 1,
num7: 1,
num8: 1
2016-11-10 21:46:55 +08:00
}
},
methods: {
handleChange(value) {
console.log(value);
}
}
};
< / script >
2016-11-10 23:50:55 +08:00
2017-05-18 12:28:45 +08:00
< style >
.demo-box.demo-input-number {
.el-input-number + .el-input-number {
margin-left: 10px;
}
}
< / style >
2016-11-10 21:46:55 +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 >
< el-input-number v-model = "num1" @change =" handleChange " :min = "1" :max = "10" ></ el-input-number >
< / template >
< script >
export default {
data() {
return {
num1: 1
};
},
methods: {
2016-11-14 18:10:52 +08:00
handleChange(value) {
console.log(value)
}
2016-11-10 21:46:55 +08:00
}
};
< / script >
```
:::
### 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 = "num2" :disabled = "true" > < / el-input-number >
< / template >
< script >
export default {
data() {
return {
num2: 1
}
}
};
< / script >
```
:::
### Steps
Allows you to define incremental steps.
:::demo Add `step` attribute to set the step.
```html
< template >
< el-input-number v-model = "num3" :step = "2" > < / el-input-number >
< / template >
< script >
export default {
data() {
return {
num3: 5
}
}
};
< / script >
```
:::
2017-01-16 10:42:32 +08:00
### Size
2017-09-22 17:46:34 +08:00
Use attribute `size` to set additional sizes with `medium` , `small` or `mini` .
2017-01-16 10:42:32 +08:00
:::demo
```html
< template >
2017-09-22 17:46:34 +08:00
< el-input-number v-model = "num4" > < / el-input-number >
< el-input-number size = "medium" v-model = "num5" > < / el-input-number >
< el-input-number size = "small" v-model = "num6" > < / el-input-number >
< el-input-number size = "mini" v-model = "num7" > < / el-input-number >
2017-01-16 10:42:32 +08:00
< / template >
< script >
export default {
data() {
return {
num4: 1,
num5: 1,
2017-09-22 17:46:34 +08:00
num6: 1,
num7: 1
}
}
};
< / script >
```
:::
### Controls Position
2017-09-23 12:46:37 +08:00
:::demo Set `controls-position` to decide the position of control buttons.
2017-09-22 17:46:34 +08:00
```html
< template >
< el-input-number v-model = "num8" controls-position = "right" @change =" handleChange " :min = "1" :max = "10" ></ el-input-number >
< / template >
< script >
export default {
data() {
return {
num8: 1
};
},
methods: {
handleChange(value) {
console.log(value);
2017-01-16 10:42:32 +08:00
}
}
};
< / script >
```
:::
2016-11-10 21:46:55 +08:00
### Attributes
| Attribute | Description | Type | Accepted Values | Default |
|----| ----| ---| ----| -----|
|value | binding value| number | — | — |
2018-01-26 10:53:53 +08:00
|min | the minimum allowed value | number | — | `-Infinity` |
2016-11-10 21:46:55 +08:00
|max | the maximum allowed value | number | — | `Infinity` |
|step | incremental step | number | — | 1 |
|size | size of the component | string | large/small| — |
|disabled| whether the component is disabled | boolean | — | false |
2016-11-30 18:16:49 +08:00
|controls| whether to enable the control buttons | boolean | — | true |
2017-09-22 17:46:34 +08:00
|controls-position | position of the control buttons | string | right | - |
2017-07-30 16:26:05 +08:00
|name | same as `name` in native input | string | — | — |
2017-09-29 15:58:07 +08:00
|label | label text | string | — | — |
2016-11-10 21:46:55 +08:00
### Events
| Event Name | Description | Parameters |
|----| ---- | -----|
2017-07-17 18:24:24 +08:00
|change | triggers when the value changes | value after change |
2017-07-18 12:09:03 +08:00
| blur | triggers when Input blurs | (event: Event) |
| focus | triggers when Input focuses | (event: Event) |
2017-07-18 13:47:35 +08:00
### Methods
| Method | Description | Parameters |
|------|--------|-------|
| focus | focus the Input component | - |