【问题标题】:The radio button <b-form-radio-group> is not checked (turning blue)单选按钮 <b-form-radio-group> 未选中(变为蓝色)
【发布时间】:2020-02-10 16:14:10
【问题描述】:

我正在使用Bootstrap-vue.JS 制作一组单选按钮。我有一个重置功能来检查其中一个单选按钮。当我调用该函数时,单选按钮的值按我的预期发生了变化,但单选按钮本身并没有显示它的变化(圆圈没有变成蓝色)

这是模板

<b-row md="9" align-h="center">
 <b-form-group>
  <b-form-radio-group
   id="radio-group-1"
   v-model="voc_type"
   name="radio-options"
  >
   <b-form-radio value="Request">Request</b-form-radio>
   <b-form-radio value="Complain">Complain</b-form-radio>
   <b-form-radio value="Saran">Saran</b-form-radio>
   <b-form-radio value="Pujian">Pujian</b-form-radio>
  </b-form-radio-group>
 </b-form-group>
</b-row>
{{ voc_type }}

这是创建vue 时的初始化

export default{
 data{
  return{
   voc_type: 'Request',
  }
 }
}

这里是重置功能

reset(){
 this.voc_type= 'Request'
}

当我调用reset() 时,{{ voc_type }} 的输出正如我预期的那样是“请求”,但单选按钮没有变成蓝色。 idk为什么..

【问题讨论】:

    标签: vue.js bootstrap-4 radio-button radio-group bootstrap-vue


    【解决方案1】:

    我实现了一个重置​​按钮,它现在按预期工作:

    <template>
      <div>
        <b-row md="9" align-h="center">
          <b-form-group>
            <b-form-radio-group id="radio-group-1" v-model="voc_type" name="radio-options">
              <b-form-radio value="Request">Request</b-form-radio>
              <b-form-radio value="Complain">Complain</b-form-radio>
              <b-form-radio value="Saran">Saran</b-form-radio>
              <b-form-radio value="Pujian">Pujian</b-form-radio>
            </b-form-radio-group>
          </b-form-group>
        </b-row>
        {{ voc_type }}
        <b-btn @click="reset()">Reset</b-btn>
      </div>
    </template>
    
    <script>
    export default {
      data() {
        return {
          voc_type: 'Request'
        };
      },
      methods: {
        reset() {
          this.voc_type = 'Request';
        }
      }
    };
    </script>
    

    您的数据函数中有错字,因此 Vue 反应性可能无法正常工作

      data() { <-- correct this line 
        return {
          voc_type: 'Request'
        };
      },
    

    【讨论】:

    • 对不起,我在那个数据函数中有错字,我的真实代码很好。但是现在看到我的代码可以正常工作真的很奇怪,我还没有对我的代码进行任何更改.. 嗯:V 感谢您的回答..
    猜你喜欢
    • 2021-07-08
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多