2020-08-13 15:18:26 +08:00
## Radio
Boutons de sélection entre plusieurs options.
### Usage
Radio ne devrait pas avoir trop d'options. Dans ce cas utilisez plutôt Select.
:::demo Créer un composant Radio est facile, vous avez juste besoin de lier les `v-model` des options. Chacun équivaut à la valeur de `label` du radio correspondant. Le type de `label` est `String` , `Number` ou `Boolean` .
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
```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 {
2021-09-04 19:29:28 +08:00
data() {
2020-08-13 15:18:26 +08:00
return {
2021-08-27 20:31:40 +08:00
radio1: '1',
radio2: '1',
radio3: '1',
radio4: '1',
2021-09-04 19:29:28 +08:00
}
},
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
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Désactivé
L'attribut `disabled` désactive le radio.
:::demo Ajoutez simplement l'attribut `disabled` au radio.
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
```html
< template >
< el-radio disabled v-model = "radio" label = "disabled" > Option A< / el-radio >
2021-09-04 19:29:28 +08:00
< el-radio disabled v-model = "radio" label = "selected and disabled"
>Option B< /el-radio
>
2020-08-13 15:18:26 +08:00
< / template >
< script >
export default {
2021-09-04 19:29:28 +08:00
data() {
2020-08-13 15:18:26 +08:00
return {
2021-09-04 19:29:28 +08:00
radio: 'selected and disabled',
}
},
2020-08-13 15:18:26 +08:00
}
< / 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
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Groupe de boutons radio
Utile pour choisir entre plusieurs groupes d'options mutuellement exclusives.
:::demo Combinez `el-radio-group` avec `el-radio` pour afficher un groupe de radios. Liez une variable au `v-model` de `el-radio-group` et configurez le label dans `el-radio` . Cet élément fournit aussi l'évènement `change` qui a en paramètre la valeur courante.
```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 {
2021-09-04 19:29:28 +08:00
data() {
2020-08-13 15:18:26 +08:00
return {
2021-09-04 19:29:28 +08:00
radio: 3,
}
},
2020-08-13 15:18:26 +08:00
}
< / 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
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Style bouton
Des radios affichés comme des boutons standards.
:::demo Changez simplement `el-radio` pour `el-radio-button` . L'attribut `size` permet de régler la taille.
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
```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" >
2021-09-04 19:29:28 +08:00
< el-radio-button label = "New York" > < / el-radio-button >
2020-08-13 15:18:26 +08:00
< 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 >
2021-09-04 19:29:28 +08:00
< el-radio-button label = "Washington" disabled > < / el-radio-button >
2020-08-13 15:18:26 +08:00
< 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 {
2021-09-04 19:29:28 +08:00
data() {
2020-08-13 15:18:26 +08:00
return {
radio1: 'New York',
radio2: 'New York',
radio3: 'New York',
2021-09-04 19:29:28 +08:00
radio4: 'New York',
}
},
2020-08-13 15:18:26 +08:00
}
< / 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
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Avec bordures
:::demo L'attribut `border` ajoute une bordure aux radios.
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
```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" >
2021-09-04 19:29:28 +08:00
< 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
>
2020-08-13 15:18:26 +08:00
< / 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 {
2021-09-04 19:29:28 +08:00
data() {
2020-08-13 15:18:26 +08:00
return {
radio1: '1',
radio2: '1',
radio3: '1',
2021-09-04 19:29:28 +08:00
radio4: '1',
}
},
2020-08-13 15:18:26 +08:00
}
< / 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
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Attributs de Radio
2021-09-04 19:29:28 +08:00
| Attribut | Description | Type | Valeurs acceptées | Défaut |
| --------------------- | -------------------------------------------------- | ------------------------- | --------------------- | ------ |
| model-value / v-model | La valeur liée. | string / number / boolean | — | — |
| label | La valeur du radio. | string / number / boolean | — | — |
| disabled | Si le radio est désactivé. | boolean | — | false |
| border | Si une bordure doit être affichée autour du radio. | boolean | — | false |
| size | Taille du radio | string | medium / small / mini | — |
| name | Attribut 'name' natif. | string | — | — |
2020-08-13 15:18:26 +08:00
### Évènements de Radio
2021-09-04 19:29:28 +08:00
| Nom | Description | Paramètres |
| ------ | ------------------------------------ | ------------------- |
2020-08-13 15:18:26 +08:00
| change | Se déclenche quand la valeur change. | La valeur du label. |
### Attributs de Radio-group
2021-09-04 19:29:28 +08:00
| Attribut | Description | Type | Valeurs acceptées | Défaut |
| --------------------- | ----------------------------------------------------- | ------------------------- | --------------------- | ------- |
| model-value / v-model | La valeur liée. | string / number / boolean | — | — |
| size | Taille des radios. | string | medium / small / mini | — |
| disabled | Si les radios sont désactivés. | boolean | — | false |
| text-color | Couleur du texte quand le bouton est actif. | string | — | #ffffff |
| fill | Bordure et couleur de fond quand le bouton est actif. | string | — | #409EFF |
2020-08-13 15:18:26 +08:00
### Évènements de Radio-group
2021-09-04 19:29:28 +08:00
| Nom | Description | Paramètres |
| ------ | ------------------------------------ | ------------------- |
2020-08-13 15:18:26 +08:00
| change | Se déclenche quand la valeur change. | La valeur du label. |
### Attributs Radio-button
2021-09-04 19:29:28 +08:00
| Attribut | Description | Type | Valeurs acceptées | Défaut |
| -------- | -------------------------- | --------------- | ----------------- | ------ |
| label | Valeur du radio. | string / number | — | — |
| disabled | Si le radio est désactivé. | boolean | — | false |
| name | Attribut 'name' natif. | string | — | — |