ant design vue的单选框radio回显问题

代码块1:
<template>
  <div>
    <a-radio-group v-model="rruleForm.adioValue">
        <a-radio value='0'>男</a-radio>
        <a-radio value='1'>女</a-radio>
      </a-radio-group>
  </div>
</template>

<script>
export default {
  data() {
    return {
    	ruleForm: {
    		radioValue: "",
    	}
    };
  },
};
</script>

以上是原代码,当后台返回数据radioValue为1时,页面能正常回显,但是发现不能选择了,后来改为以下代码:

代码块2:
<template>
  <div>
    <a-radio-group  :defaultValue="Number(ruleForm.radioValue)">
        <a-radio :value='0'>男</a-radio>
        <a-radio :value='1'>女</a-radio>
      </a-radio-group>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
    		radioValue: "",
    	}
    };
  },
};
</script>

这样能回显也能选择了,但是没有v-model不能实时获取到单选框的值,最终用

this.$set(this.ruleForm,'radioValue',res.data.radioValue)
//res.data.radioValue是后台返回的值,还是使用代码块1

猜你喜欢

转载自blog.csdn.net/weixin_45629194/article/details/109744649