# Radio 单选框

表单类型组件,结合form组件使用

# 基础用法

<wx-form ref="form">
  <wx-form-body>
    <wx-form-group type="radio" title="默认选中">
      <wx-radio v-model="v1" :options="options1" name="rd1"></wx-radio>
    </wx-form-group>
  </wx-form-body>
</wx-form>

<script>
export default {
  data() {
    return {
      options1: [
        { label: "男", value: "male" },
        { label: "女", value: "female" }
      ],
      v1: "male"
    };
  }
};
</script>

# 数据校验

<wx-form ref="form">
  <wx-form-body>
    <wx-form-group type="radio" title="数据校验">
      <wx-radio v-model="v2" :options="options2" name="rd2" required empty-tips="请选择学历"></wx-radio>
    </wx-form-group>
  </wx-form-body>
  <wx-form-tips>选中值:{{v2}}</wx-form-tips>
  <wx-form-action>
    <wx-button @click="handleClick">确定</wx-button>
  </wx-form-action>
</wx-form>

<script>
export default {
  data() {
    return {
      options2: [
        { label: "本科", value: "1" },
        { label: "硕士", value: "2" },
        { label: "博士", value: "3" },
        { label: "其他 (不可选)", value: "4", disabled: true }
      ],
      v2: ""
    };
  },
  methods: {
    handleClick() {
      this.$refs.form.validate(error => {
        if (error) {
          this.$tooltip(error)
        } else {
          this.$toast("验证成功", { type: "success" })
        }
      });
    }
  }
};
</script>

# Radio Attributes

参数 说明 类型 可选值 默认值
v-model/value 绑定值 String/Number - -
name 原生 name 属性 String - -
options 可选项数组,required Array - -
required 是否必选 Boolean - false
emptyTips 未选校验提示信息 String - -

options 格式说明

[
  { label: "", value: "" },
  { label: "", value: "", disabled: true }
]
back
单选框