2020-08-13 15:18:26 +08:00
## Radio
Selección única entre múltiples opciones.
### Uso básico
El elemento Radio no debe tener muchas opciones. De otra manera, utilice el componente Select.
:::demo Crear un elemento Radio es fácil, solo necesita enlazar(`bind`) una variable a la directiva `v-model` del Radio. Va a ser igual al valor `label` del Radio seleccionado. El tipo de dato de `label` es `String` , `Number` o `Boolean` .
```html
< template >
2021-08-27 20:31:40 +08:00
< div >
< el-radio v-model = "radio1" label = "1" > Option 1< / el-radio >
< el-radio v-model = "radio1" label = "2" > Option 2< / el-radio >
< / div >
< div >
< el-radio v-model = "radio2" label = "1" size = "medium" > Option 1< / el-radio >
< el-radio v-model = "radio2" label = "2" size = "medium" > Option 2< / el-radio >
< / div >
< div >
< el-radio v-model = "radio3" label = "1" size = "small" > Option 1< / el-radio >
< el-radio v-model = "radio3" label = "2" size = "small" > Option 2< / el-radio >
< / div >
< div >
< el-radio v-model = "radio4" label = "1" size = "mini" > Option 1< / el-radio >
< el-radio v-model = "radio4" label = "2" size = "mini" > Option 2< / el-radio >
< / div >
2020-08-13 15:18:26 +08:00
< / template >
< script >
export default {
data () {
return {
2021-08-27 20:31:40 +08:00
radio1: '1',
radio2: '1',
radio3: '1',
radio4: '1',
2020-08-13 15:18:26 +08:00
};
}
}
< / script >
2021-05-31 14:58:41 +08:00
<!--
< setup >
2021-07-16 10:53:22 +08:00
import { defineComponent, ref } from 'vue'
2021-05-31 14:58:41 +08:00
2021-07-16 10:53:22 +08:00
export default defineComponent({
2021-05-31 14:58:41 +08:00
setup() {
2021-07-16 10:53:22 +08:00
return {
2021-08-27 20:31:40 +08:00
radio1: ref('1'),
radio2: ref('1'),
radio3: ref('1'),
radio4: ref('1'),
2021-07-16 10:53:22 +08:00
}
2021-05-31 14:58:41 +08:00
}
2021-07-16 10:53:22 +08:00
})
2021-05-31 14:58:41 +08:00
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
:::
### Deshabilitado
El atributo `disabled` es utilizado para deshabilitar un Radio.
:::demo Solo necesita agregar el atributo `disabled` .
```html
< template >
< el-radio disabled v-model = "radio" label = "disabled" > Option A< / el-radio >
< el-radio disabled v-model = "radio" label = "selected and disabled" > Option B< / el-radio >
< / template >
< script >
export default {
data () {
return {
radio: 'selected and disabled'
};
}
}
< / script >
2021-06-30 15:11:12 +08:00
<!--
< setup >
2021-07-16 10:53:22 +08:00
import { defineComponent, ref } from 'vue'
2021-06-30 15:11:12 +08:00
export default defineComponent({
setup() {
return {
radio: ref('selected and disabled'),
2021-07-16 10:53:22 +08:00
}
}
})
2021-06-30 15:11:12 +08:00
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
:::
### Grupo de elementos Radio
Recomendado para seleccionar opciones que se excluyen mutuamente.
:::demo Combine `el-radio-group` con `el-radio` para mostrar un grupo de Radios. Enlace la variable con `v-model` del elemento `el-radio-group` y asigne el valor del `label` en `el-radio` . Se provee el evento `change` con el valor actual como parámetro.
```html
< el-radio-group v-model = "radio" >
< el-radio :label = "3" > Option A< / el-radio >
< el-radio :label = "6" > Option B< / el-radio >
< el-radio :label = "9" > Option C< / el-radio >
< / el-radio-group >
< script >
export default {
data () {
return {
radio: 3
};
}
}
< / script >
2021-06-30 15:11:12 +08:00
<!--
< setup >
2021-07-16 10:53:22 +08:00
import { defineComponent, ref } from 'vue'
2021-06-30 15:11:12 +08:00
export default defineComponent({
setup() {
return {
radio: ref(3),
2021-07-16 10:53:22 +08:00
}
}
})
2021-06-30 15:11:12 +08:00
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
:::
### Estilo Button
Radio con estilo de botón.
:::demo Solo necesita cambiar el elemento `el-radio` a `el-radio-button` . Se provee el atributo `size` .
```html
< template >
< div >
< el-radio-group v-model = "radio1" >
< el-radio-button label = "New York" > < / el-radio-button >
< el-radio-button label = "Washington" > < / el-radio-button >
< el-radio-button label = "Los Angeles" > < / el-radio-button >
< el-radio-button label = "Chicago" > < / el-radio-button >
< / el-radio-group >
< / div >
< div style = "margin-top: 20px" >
< el-radio-group v-model = "radio2" size = "medium" >
< el-radio-button label = "New York" > < / el-radio-button >
< el-radio-button label = "Washington" > < / el-radio-button >
< el-radio-button label = "Los Angeles" > < / el-radio-button >
< el-radio-button label = "Chicago" > < / el-radio-button >
< / el-radio-group >
< / div >
< div style = "margin-top: 20px" >
< el-radio-group v-model = "radio3" size = "small" >
< el-radio-button label = "New York" > < / el-radio-button >
< el-radio-button label = "Washington" disabled > < / el-radio-button >
< el-radio-button label = "Los Angeles" > < / el-radio-button >
< el-radio-button label = "Chicago" > < / el-radio-button >
< / el-radio-group >
< / div >
< div style = "margin-top: 20px" >
< el-radio-group v-model = "radio4" disabled size = "mini" >
< el-radio-button label = "New York" > < / el-radio-button >
< el-radio-button label = "Washington" > < / el-radio-button >
< el-radio-button label = "Los Angeles" > < / el-radio-button >
< el-radio-button label = "Chicago" > < / el-radio-button >
< / el-radio-group >
< / div >
< / template >
< script >
export default {
data () {
return {
radio1: 'New York',
radio2: 'New York',
radio3: 'New York',
radio4: 'New York'
};
}
}
< / script >
2021-06-30 15:11:12 +08:00
<!--
< setup >
2021-07-16 10:53:22 +08:00
import { defineComponent, ref } from 'vue'
2021-06-30 15:11:12 +08:00
export default defineComponent({
setup() {
return {
radio1: ref('New York'),
radio2: ref('New York'),
radio3: ref('New York'),
radio4: ref('New York'),
2021-07-16 10:53:22 +08:00
}
}
})
2021-06-30 15:11:12 +08:00
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
:::
### Con bordes
:::demo El atributo `border` agrega un borde al elemento Radio.
```html
< template >
< div >
< el-radio v-model = "radio1" label = "1" border > Option A< / el-radio >
< el-radio v-model = "radio1" label = "2" border > Option B< / el-radio >
< / div >
< div style = "margin-top: 20px" >
< el-radio v-model = "radio2" label = "1" border size = "medium" > Option A< / el-radio >
< el-radio v-model = "radio2" label = "2" border size = "medium" > Option B< / el-radio >
< / div >
< div style = "margin-top: 20px" >
< el-radio-group v-model = "radio3" size = "small" >
< el-radio label = "1" border > Option A< / el-radio >
< el-radio label = "2" border disabled > Option B< / el-radio >
< / el-radio-group >
< / div >
< div style = "margin-top: 20px" >
< el-radio-group v-model = "radio4" size = "mini" disabled >
< el-radio label = "1" border > Option A< / el-radio >
< el-radio label = "2" border > Option B< / el-radio >
< / el-radio-group >
< / div >
< / template >
< script >
export default {
data () {
return {
radio1: '1',
radio2: '1',
radio3: '1',
radio4: '1'
};
}
}
< / script >
2021-06-30 15:11:12 +08:00
<!--
< setup >
2021-07-16 10:53:22 +08:00
import { defineComponent, ref } from 'vue'
2021-06-30 15:11:12 +08:00
export default defineComponent({
setup() {
return {
radio1: ref('1'),
radio2: ref('1'),
radio3: ref('1'),
radio4: ref('1'),
2021-07-16 10:53:22 +08:00
}
}
})
2021-06-30 15:11:12 +08:00
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
:::
### Atributos de Radio
| Atributo | Descripción | Tipo | Valores Aceptado | Por defecto |
| -------- | ---------------------------------------- | ------------------------- | --------------------- | ----------- |
2021-05-24 11:10:53 +08:00
| model-value / v-model | valor enlazado | string / number / boolean | — | — |
2020-08-13 15:18:26 +08:00
| label | el valor del Radio | string / number / boolean | — | — |
| disabled | si el Radio está deshabilitado | boolean | — | false |
| border | agregar borde alrededor del elemento Radio | boolean | — | false |
2021-08-27 20:31:40 +08:00
| size | tamaño del elemento Radio | string | medium / small / mini | — |
2020-08-13 15:18:26 +08:00
| name | atributo nativo `name` | string | — | — |
### Atributos de Radio-button
| Atributo | Descripción | Tipo | Valores Aceptado | Por defecto |
| -------- | ------------------------------ | --------------- | ---------------- | ----------- |
| label | el valor del Radio | string / number | — | — |
| disabled | si el Radio está deshabilitado | boolean | — | false |
| name | atributo nativo `name` | string | — | — |
### Atributos de Radio-group
| Atributo | Descripción | Tipo | Valores Aceptado | Valores por defecto |
| ---------- | ---------------------------------------- | ------- | --------------------- | ------------------- |
2021-05-24 11:10:53 +08:00
| model-value / v-model | valor enlazado | string / number / boolean | — | — |
2021-08-27 20:31:40 +08:00
| size | the size of radio | string | medium / small / mini | — |
2020-08-13 15:18:26 +08:00
| disabled | si la anidación de radios está deshabilitada | boolean | — | false |
| text-color | color de las letras cuando el botón está activo | string | — | #ffffff |
| fill | color del borde y fondo cuando el botón está activo | string | — | #409EFF |
2021-05-24 11:10:53 +08:00
### Eventos de Radio
2020-08-13 15:18:26 +08:00
| Nombre de evento | Descripción | Parámetros |
| ---------------- | --------------------------------- | ---------------------------------------- |
| change | se dispara cuando el valor cambia | el valor del `label` del Radio seleccionado |
2021-05-24 11:10:53 +08:00
### Eventos de Radio-group
2020-08-13 15:18:26 +08:00
| Nombre de evento | Descripción | Parámetros |
| ---------------- | --------------------------------- | ---------------------------------------- |
| change | se dispara cuando el valor cambia | el valor del `label` del Radio seleccionado |