2016-11-10 13:46:55 +00:00
< script >
module.exports = {
data() {
return {
radio: '1',
radio1: 'selected and disabled',
radio2: 3,
radio3: ''
};
}
};
< / script >
## Radio
2016-11-11 11:06:27 +00:00
Single selection among multiple options.
2016-11-10 13:46:55 +00:00
2016-11-11 11:06:27 +00:00
### Basic usage
2016-11-10 13:46:55 +00:00
2016-11-11 11:06:27 +00:00
Radio should not have too many options. Otherwise, use the Select component instead.
2016-11-10 13:46:55 +00:00
2016-11-11 11:06:27 +00:00
:::demo Creating a radio component is easy, you just need to bind a variable to Radio's `v-model` . It equals to the value of `label` of the chosen radio. The type of `label` is `String` or `Number` .
2016-11-10 13:46:55 +00:00
```html
< template >
< el-radio class = "radio" v-model = "radio" label = "1" > optionA< / el-radio >
< el-radio class = "radio" v-model = "radio" label = "2" > optionB< / el-radio >
< / template >
< script >
export default {
data () {
return {
2016-11-14 10:10:52 +00:00
radio: '1'
2016-11-10 13:46:55 +00:00
};
}
}
< / script >
```
:::
### Disabled
2016-11-11 11:06:27 +00:00
`disabled` attribute is used to disable the radio.
2016-11-10 13:46:55 +00:00
2016-11-11 11:06:27 +00:00
:::demo You just need to add the `disabled` attribute.
2016-11-10 13:46:55 +00:00
```html
< template >
2016-11-11 11:06:27 +00:00
< el-radio disabled v-model = "radio1" label = "disabled" > optionA< / el-radio >
2016-11-10 13:46:55 +00:00
< el-radio disabled v-model = "radio1" label = "selected and disabled" > optionB< / el-radio >
< / template >
< script >
export default {
data () {
return {
radio1: 'selected and disabled'
};
}
}
< / script >
```
:::
### Radio button group
2016-11-11 11:06:27 +00:00
Suitable for choosing from some mutually exclusive options.
2016-11-10 13:46:55 +00:00
2016-11-11 11:06:27 +00:00
:::demo Combine `<el-radio-group>` with `<el-radio>` to display a radio group. Bind a variable with `v-model` of `<el-radio-group>` element and set label value in `<el-radio>` . It also provides `change` event with the current value as its parameter.
2016-11-10 13:46:55 +00:00
```html
< el-radio-group v-model = "radio2" >
< el-radio :label = "3" > optionA< / el-radio >
< el-radio :label = "6" > optionB< / el-radio >
< el-radio :label = "9" > optionC< / el-radio >
< / el-radio-group >
2016-11-14 10:10:52 +00:00
< script >
export default {
data () {
return {
radio2: 3
};
}
}
< / script >
2016-11-10 13:46:55 +00:00
```
:::
### Button style
Radio with button styles.
2016-11-11 11:06:27 +00:00
:::demo You just need to change `<el-radio>` element into `<el-radio-button>` element. We also provide `size` attribute for these buttons: `large` and `small` .
2016-11-10 13:46:55 +00:00
```html
< el-radio-group v-model = "radio3" >
2016-11-11 11:06:27 +00:00
< el-radio-button label = "New York" > < / el-radio-button >
< el-radio-button label = "Washington" > < / el-radio-button >
2016-11-10 13:46:55 +00:00
< el-radio-button label = "Los Angeles" :disabled = "true" > < / el-radio-button >
< el-radio-button label = "Chicago" > < / el-radio-button >
< / el-radio-group >
2016-11-11 11:06:27 +00:00
< script >
export default {
data () {
return {
radio3: ''
};
}
}
< / script >
```
2016-11-10 13:46:55 +00:00
:::
### Radio Attributes
2016-11-11 11:06:27 +00:00
Attribute | Description | Type | Accepted Values | Default
2016-11-10 13:46:55 +00:00
---- | ---- | ---- | ---- | ----
2016-11-11 11:06:27 +00:00
label | the value of radio | string/number | — | —
disabled | whether radio is disabled | boolean | — | false
2016-11-14 04:16:13 +00:00
name | native 'name' attribute | string | — | —
2016-11-10 13:46:55 +00:00
### Radio-group Attributes
2016-11-11 11:06:27 +00:00
Attribute | Description | Type | Accepted Values | Default
2016-11-10 13:46:55 +00:00
---- | ---- | ---- | ---- | ----
2016-11-11 11:06:27 +00:00
size | the size of radio buttons | string | large/small | —
2016-11-10 13:46:55 +00:00
### Radio-group Events
2016-11-11 11:06:27 +00:00
| Event Name | Description | Parameters |
2016-11-10 13:46:55 +00:00
--- | --- | ---
2016-11-11 11:06:27 +00:00
change | triggers when the bound value changes | the label value of the chosen radio
2016-11-10 13:46:55 +00:00
### Radio-button Attributes
2016-11-11 11:06:27 +00:00
Attribute | Description | Type | Accepted Values | Default
2016-11-10 13:46:55 +00:00
---- | ---- | ---- | ---- | ----
2016-11-11 11:06:27 +00:00
label | the value of radio | string/number | — | —
disabled | whether radio is disabled | boolean | — | false
2016-11-26 09:54:27 +00:00
fill | border and background color when button is active | string | — | #20a0ff |
text-color | font color when button is active | string | — | #ffffff |
2016-11-10 13:46:55 +00:00