Radio 单选

概述

基本组件-单选框。主要用于一组可选项单项选择,或者单独用于切换到选中状态。

使用指南

在 .json 中引入组件

  1. "usingComponents": {
  2. "i-radio-group": "../../dist/radio-group/index",
  3. "i-radio": "../../dist/radio/index"
  4. }

示例

  1. <i-panel title="group-水果">
  2. <i-radio-group current="{{current}}" bindchange="handleFruitChange">
  3. <i-radio wx:for="{{fruit}}" position="{{position}}" wx:key="{{item.id}}" value="{{item.name}}">
  4. </i-radio>
  5. </i-radio-group>
  6. </i-panel>
  7. <i-button bindclick="handleClick" type="ghost">切换单选框位置</i-button>
  8. <i-panel title="radio-动物">
  9. <i-radio value="{{animal}}" disabled="{{disabled}}" checked="{{checked}}" bindchange="handleAnimalChange">
  10. </i-radio>
  11. </i-panel>
  12. <i-button bindclick="handleDisabled" type="ghost">切换disabled状态</i-button>
  1. Page({
  2. data: {
  3. fruit: [{
  4. id: 1,
  5. name: '香蕉',
  6. }, {
  7. id: 2,
  8. name: '苹果'
  9. }, {
  10. id: 3,
  11. name: '西瓜'
  12. }, {
  13. id: 4,
  14. name: '葡萄',
  15. }],
  16. current: '苹果',
  17. position: 'left',
  18. animal: '熊猫',
  19. checked: false,
  20. disabled: false,
  21. },
  22. handleFruitChange({ detail = {} }) {
  23. this.setData({
  24. current: detail.value
  25. });
  26. },
  27. handleClick() {
  28. this.setData({
  29. position: this.data.position.indexOf('left') !== -1 ? 'right' : 'left',
  30. });
  31. },
  32. handleDisabled() {
  33. this.setData({
  34. disabled: !this.data.disabled
  35. });
  36. },
  37. handleAnimalChange({ detail = {} }) {
  38. this.setData({
  39. checked: detail.current
  40. });
  41. },
  42. });

API

RadioGroup properties

属性说明类型默认值
i-class自定义 class 类名String-
current指定当前选中的项目 valueString-

RadioGroup events

事件名说明返回值
bind:change切换选项时触发current

Radio properties

属性说明类型默认值
i-class自定义 class 类名String-
value当前项的 valueString-
checked当前项是否选中Booleanfalse
disabled是否禁用当前项Booleanfalse
color主题色String-
position位置,可选值为 left 或 rightStringleft

Radio events

事件名说明返回值
bind:change切换选项时触发current