2016-07-27 14:15:02 +08:00
|
|
|
|
<script>
|
|
|
|
|
module.exports = {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2016-09-09 12:28:56 +08:00
|
|
|
|
radio: '1',
|
2016-07-27 14:15:02 +08:00
|
|
|
|
radio1: '选中且禁用',
|
|
|
|
|
radio2: 3,
|
2017-01-16 10:43:10 +08:00
|
|
|
|
radio3: '上海',
|
|
|
|
|
radio4: '上海',
|
2017-08-25 13:37:56 +08:00
|
|
|
|
radio5: '上海',
|
|
|
|
|
radio6: '上海',
|
|
|
|
|
radio7: '1',
|
|
|
|
|
radio8: '1',
|
|
|
|
|
radio9: '1',
|
|
|
|
|
radio10: '1'
|
2016-07-27 14:15:02 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
## Radio 单选框
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
在一组备选项中进行单选
|
2016-08-23 18:32:28 +08:00
|
|
|
|
|
2016-09-09 12:28:56 +08:00
|
|
|
|
### 基础用法
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-09-09 12:28:56 +08:00
|
|
|
|
由于选项默认可见,不宜过多,若选项过多,建议使用 Select 选择器。
|
2016-08-26 18:34:54 +08:00
|
|
|
|
|
2017-08-25 13:37:56 +08:00
|
|
|
|
:::demo 要使用 Radio 组件,只需要设置`v-model`绑定变量,选中意味着变量的值为相应 Radio `label`属性的值,`label`可以是`String`、`Number`或`Boolean`。
|
2016-08-23 18:32:28 +08:00
|
|
|
|
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2017-08-25 13:37:56 +08:00
|
|
|
|
<el-radio v-model="radio" label="1">备选项</el-radio>
|
|
|
|
|
<el-radio v-model="radio" label="2">备选项</el-radio>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
2016-11-09 16:02:16 +08:00
|
|
|
|
radio: '1'
|
2016-08-23 18:32:28 +08:00
|
|
|
|
};
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-26 18:34:54 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-09-06 12:47:25 +08:00
|
|
|
|
### 禁用状态
|
|
|
|
|
|
|
|
|
|
单选框不可用的状态。
|
|
|
|
|
|
2017-08-25 13:37:56 +08:00
|
|
|
|
:::demo 只要在`el-radio`元素中设置`disabled`属性即可,它接受一个`Boolean`,`true`为禁用。
|
2016-09-06 12:47:25 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-09-09 12:28:56 +08:00
|
|
|
|
<el-radio disabled v-model="radio1" label="禁用">备选项</el-radio>
|
|
|
|
|
<el-radio disabled v-model="radio1" label="选中且禁用">备选项</el-radio>
|
2016-09-06 12:47:25 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
radio1: '选中且禁用'
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
|
|
|
|
### 单选框组
|
2016-08-23 18:32:28 +08:00
|
|
|
|
|
2016-09-09 12:28:56 +08:00
|
|
|
|
适用于在多个互斥的选项中选择的场景
|
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
:::demo 结合`el-radio-group`元素和子元素`el-radio`可以实现单选组,在`el-radio-group`中绑定`v-model`,在`el-radio`中设置好`label`即可,无需再给每一个`el-radio`绑定变量,另外,还提供了`change`事件来响应变化,它会传入一个参数`value`。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
|
|
|
|
```html
|
2016-11-09 16:02:16 +08:00
|
|
|
|
<template>
|
|
|
|
|
<el-radio-group v-model="radio2">
|
|
|
|
|
<el-radio :label="3">备选项</el-radio>
|
|
|
|
|
<el-radio :label="6">备选项</el-radio>
|
|
|
|
|
<el-radio :label="9">备选项</el-radio>
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
radio2: 3
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```
|
2016-08-26 18:34:54 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-09-06 12:47:25 +08:00
|
|
|
|
### 按钮样式
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-09-06 12:47:25 +08:00
|
|
|
|
按钮样式的单选组合。
|
2016-08-26 18:34:54 +08:00
|
|
|
|
|
2017-08-25 13:37:56 +08:00
|
|
|
|
:::demo 只需要把`el-radio`元素换成`el-radio-button`元素即可,此外,Element 还提供了`size`属性。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
2016-11-09 16:02:16 +08:00
|
|
|
|
<template>
|
2017-08-25 13:37:56 +08:00
|
|
|
|
<div>
|
|
|
|
|
<el-radio-group v-model="radio3">
|
|
|
|
|
<el-radio-button label="上海"></el-radio-button>
|
|
|
|
|
<el-radio-button label="北京"></el-radio-button>
|
|
|
|
|
<el-radio-button label="广州"></el-radio-button>
|
|
|
|
|
<el-radio-button label="深圳"></el-radio-button>
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="margin-top: 20px">
|
|
|
|
|
<el-radio-group v-model="radio4" size="medium">
|
|
|
|
|
<el-radio-button label="上海" ></el-radio-button>
|
|
|
|
|
<el-radio-button label="北京"></el-radio-button>
|
|
|
|
|
<el-radio-button label="广州"></el-radio-button>
|
|
|
|
|
<el-radio-button label="深圳"></el-radio-button>
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="margin-top: 20px">
|
|
|
|
|
<el-radio-group v-model="radio5" size="small">
|
|
|
|
|
<el-radio-button label="上海"></el-radio-button>
|
|
|
|
|
<el-radio-button label="北京" disabled ></el-radio-button>
|
|
|
|
|
<el-radio-button label="广州"></el-radio-button>
|
|
|
|
|
<el-radio-button label="深圳"></el-radio-button>
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="margin-top: 20px">
|
|
|
|
|
<el-radio-group v-model="radio6" disabled size="mini">
|
|
|
|
|
<el-radio-button label="上海"></el-radio-button>
|
|
|
|
|
<el-radio-button label="北京"></el-radio-button>
|
|
|
|
|
<el-radio-button label="广州"></el-radio-button>
|
|
|
|
|
<el-radio-button label="深圳"></el-radio-button>
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
</div>
|
2016-11-09 16:02:16 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
2017-01-16 10:43:10 +08:00
|
|
|
|
radio3: '上海',
|
|
|
|
|
radio4: '上海',
|
2017-08-25 13:37:56 +08:00
|
|
|
|
radio5: '上海',
|
|
|
|
|
radio6: '上海'
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
|
|
|
|
### 带有边框
|
|
|
|
|
|
|
|
|
|
:::demo 设置`border`属性可以渲染为带有边框的单选框。
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<el-radio v-model="radio7" label="1" border>备选项1</el-radio>
|
|
|
|
|
<el-radio v-model="radio7" label="2" border>备选项2</el-radio>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="margin-top: 20px">
|
|
|
|
|
<el-radio v-model="radio8" label="1" border size="medium">备选项1</el-radio>
|
|
|
|
|
<el-radio v-model="radio8" label="2" border size="medium">备选项2</el-radio>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="margin-top: 20px">
|
|
|
|
|
<el-radio-group v-model="radio9" size="small">
|
|
|
|
|
<el-radio label="1" border>备选项1</el-radio>
|
|
|
|
|
<el-radio label="2" border disabled>备选项2</el-radio>
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="margin-top: 20px">
|
|
|
|
|
<el-radio-group v-model="radio10" size="mini" disabled>
|
|
|
|
|
<el-radio label="1" border>备选项1</el-radio>
|
|
|
|
|
<el-radio label="2" border>备选项2</el-radio>
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
radio7: '1',
|
|
|
|
|
radio8: '1',
|
|
|
|
|
radio9: '1',
|
|
|
|
|
radio10: '1'
|
2016-11-09 16:02:16 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```
|
2016-08-26 18:34:54 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### Radio Attributes
|
2016-07-27 14:15:02 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|
|---------- |-------- |---------- |------------- |-------- |
|
2017-08-25 13:37:56 +08:00
|
|
|
|
| label | Radio 的 value | string / number / boolean | — | — |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| disabled | 是否禁用 | boolean | — | false |
|
2017-08-25 13:37:56 +08:00
|
|
|
|
| border | 是否显示边框 | boolean | — | false |
|
|
|
|
|
| size | Radio 的尺寸,仅在 border 为真时有效 | string | medium / small / mini | — |
|
2016-11-14 12:16:13 +08:00
|
|
|
|
| name | 原生 name 属性 | string | — | — |
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2017-08-08 12:39:19 +08:00
|
|
|
|
### Radio Events
|
|
|
|
|
| 事件名称 | 说明 | 回调参数 |
|
|
|
|
|
|---------- |-------- |---------- |
|
|
|
|
|
| change | 绑定值变化时触发的事件 | 选中的 Radio label 值 |
|
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### Radio-group Attributes
|
2016-07-27 14:15:02 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|
|---------- |-------- |---------- |------------- |-------- |
|
2017-08-25 13:37:56 +08:00
|
|
|
|
| size | 单选框组尺寸,仅对按钮形式的 Radio 或带有边框的 Radio 有效 | string | medium / small / mini | — |
|
|
|
|
|
| disabled | 是否禁用 | boolean | — | false |
|
|
|
|
|
| text-color | 按钮形式的 Radio 激活时的文本颜色 | string | — | #ffffff |
|
2017-09-30 15:50:04 +08:00
|
|
|
|
| fill | 按钮形式的 Radio 激活时的填充色和边框色 | string | — | #409EFF |
|
2016-08-23 18:32:28 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### Radio-group Events
|
2016-08-23 18:32:28 +08:00
|
|
|
|
| 事件名称 | 说明 | 回调参数 |
|
|
|
|
|
|---------- |-------- |---------- |
|
|
|
|
|
| change | 绑定值变化时触发的事件 | 选中的 Radio label 值 |
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### Radio-button Attributes
|
2016-07-27 14:15:02 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|
|---------- |-------- |---------- |------------- |-------- |
|
2017-08-25 13:37:56 +08:00
|
|
|
|
| label | Radio 的 value | string / number | — | — |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| disabled | 是否禁用 | boolean | — | false |
|
2017-08-25 13:37:56 +08:00
|
|
|
|
| name | 原生 name 属性 | string | — | — |
|