Radio 单选框

Scan me!

可自定义或编辑单选框

引入

  1. import { Radio, RadioList } from 'mand-mobile'
  2. Vue.component(Radio.name, Radio)
  3. Vue.component(RadioList.name, RadioList)

代码演示

普通单选框

Radio 单选框 - 图2

  1. <template>
  2. <div class="md-example-child md-example-child-radio md-example-child-radio-0">
  3. <md-radio name="0" v-model="checked" label="单选项1" />
  4. <md-radio name="1" v-model="checked" label="单选项2" />
  5. </div>
  6. </template>
  7. <script>
  8. import {Radio} from 'mand-mobile'
  9. export default {
  10. name: 'radio-demo',
  11. components: {
  12. [Radio.name]: Radio,
  13. },
  14. data() {
  15. return {
  16. checked: '0',
  17. }
  18. },
  19. }
  20. </script>
  21.  

列表模式

Radio 单选框 - 图3

        <template>
  <div class="md-example-child md-example-child-radio md-example-child-radio-2">
    <md-field title="简单选择列表" class="radio-field">
      <md-radio-list
        v-model="myBank"
        :options="banks"
        icon-size="lg"
      />
    </md-field>
    <md-field title="输入项" class="radio-field">
      <md-radio-list
        :options="reasons"
        v-model="myReason"
        icon="right"
        icon-inverse=""
        icon-disabled=""
        icon-position="right"
        has-input
        input-label="其他"
        input-placeholder="请输入原因"
      />
    </md-field>
  </div>
</template>

<script>
import {Field, RadioList} from 'mand-mobile'

export default {
  name: 'radio-demo',
  components: {
    [Field.name]: Field,
    [RadioList.name]: RadioList,
  },
  data() {
    return {
      myBank: '',
      banks: [
        {
          value: '0',
          text: '交通银行(尾号3089)',
          brief: '选项摘要描述',
        },
        {
          value: '1',
          text: '招商银行(尾号2342)',
          brief: '选项摘要描述',
        },
        {
          value: '2',
          text: '建设银行(尾号4321)',
          brief: '选项摘要描述',
          disabled: true,
        },
      ],
      myReason: '',
      reasons: [
        {
          value: '0',
          text: '我有其他保险',
        },
        {
          value: '1',
          text: '每单都扣,我担心扣太多',
        },
        {
          value: '2',
          text: '我身体好,不需要重疾险',
        },
        {
          value: '3',
          text: '接单少,加入这个没什么用',
        },
        {
          value: '4',
          text: '我不了解这是什么计划',
        },
      ],
    }
  },
}

</script>

<style lang="stylus" scoped>
  .radio-field
    margin-bottom 40px
</style>

      

表单项内联

Radio 单选框 - 图4

        <template>
  <div class="md-example-child md-example-child-radio md-example-child-radio-1">
    <md-field>
      <md-field-item title="婚姻状况" solid>
        <md-radio name="2" v-model="marriage" label="已婚" inline />
        <md-radio name="1" v-model="marriage" label="未婚" inline />
        <md-radio name="3" v-model="marriage" label="保密" inline />
      </md-field-item>
    </md-field>
  </div>
</template>

<script>
import {Radio, Field, FieldItem} from 'mand-mobile'

export default {
  name: 'radio-demo',
  components: {
    [Field.name]: Field,
    [FieldItem.name]: FieldItem,
    [Radio.name]: Radio,
  },
  data() {
    return {
      marriage: '2',
    }
  },
}

</script>

      

API

Radio Props

属性说明类型默认值备注
v-model选中项的nameany-
name唯一键值any--
label描述文案String--
disabled是否禁用选项Booleanfalse-
inline是否内联显示Booleanfalse-
icon选中项的图标Stringchecked-
icon-inverse非选中项的图标Stringcheck-
icon-disabled禁用项的图标Stringcheck-disabled-
icon-svg使用svg图标Booleanfalse-
size图标大小Stringmd-

Radio List Props

属性说明类型默认值备注
v-model选中项的valueany-
options选项数据源Array<{text, value, disabled, …}>[]disabled为选项是否禁用
has-input是否具有可编辑项Booleanfalse-
input-label可编辑项的名称String-仅用于has-inputtrue
input-placeholder可编辑项的占位提示String-仅用于has-inputtrue
icon选中项的图标Stringchecked-
icon-inverse非选中项的图标Stringcheck-
icon-disabled禁用项的图标Stringcheck-disabled-
icon-size图标大小Stringlg-
icon-svg使用svg图标Booleanfalse-
icon-position图标位置Stringleftleft, right
is-slot-scope是否强制使用或不使用slot-scopeBoolean-某些情况下需要根据业务逻辑动态确定是否使用,可避免直接组件上加if/else

Radio List Methods

select(value)

设置选中项

参数说明类型
value选中项的valueString

Radio List Events

@change(option, index)

切换选中项事件

属性说明类型
option当前选中项的数据Object:{text, value, disabled, …}
index当前选中项的索引Number

Radio List Slots

<template>
  <md-radio-list :options="data">
    <template slot-scope="{ option }">
      <div class="custom-title" v-text="option.text"></div>
      <div class="custom-brief">{{ option.text }}的自定义描述</div>
    </template>
  </md-radio-list>
</template>