---
name: "radio"
mode: "component"
versionRequirements:
  - { name: "基础库", version: "2.10.0" }
title: "radio - 单选项目"
---

## radio

> [VERSION] 基础库 >= 2.10.0

### 描述

单选项目，搭配 radio-group 使用。

### 属性

| 属性 | 类型 | 必填 | 默认值 | 描述 |
| --- | --- | --- | --- | --- |
| `checked` | `boolean` | 否 | `false` | 是否选中 |
| `disabled` | `boolean` | 否 | `false` | 是否禁用 |
| `color` | `string` | 否 | `""` | 选中时的颜色，同 CSS color |
| `value` | `string` | 否 | - | 该项在表单中的值 |

### 示例代码

#### 基础用法

*index.tyml*

```xml
<radio-group bind:change="onChange">
  <label ty:for="{{items}}" ty:key="{{item.value}}">
    <radio value="{{item.value}}" />
    <text>{{item.name}}</text>
  </label>
</radio-group>
```

*index.tyss*

```css
label {
  display: flex;
  align-items: center;
  margin-bottom: 10rpx;
}
```

*index.js*

```javascript
Page({
  data: {
    items: [
      { value: 'a', name: 'A' },
      { value: 'b', name: 'B' },
    ],
  },
  onChange(e) {
    console.log('选中:', e.detail.value);
  },
});
```

#### 不同状态

*index.tyml*

```xml
<view class="list">
  <view class="item">
    <text>默认状态：</text>
    <radio value="default" />
  </view>
  <view class="item">
    <text>选中状态：</text>
    <radio value="checked" checked="{{true}}" />
  </view>
  <view class="item">
    <text>禁用状态：</text>
    <radio value="disabled" disabled="{{true}}" />
  </view>
  <view class="item">
    <text>自定义颜色：</text>
    <radio value="red" color="#ff0000" checked="{{true}}" />
  </view>
</view>
```

*index.tyss*

```css
.list {
  padding: 20rpx;
}
.item {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
}
```

*index.js*

```javascript
Page({});
```
