我如何在 vuejs 中检查无线电值?

Adr*_*ark 2 vue.js

到目前为止,我有这段代码,我尝试从单选按钮中获取值。我可以从 v-model 值中获取,但是使用收音机时我有一些问题。例如,如果我有更多的单选按钮,我该如何获取选中的按钮。

new Vue({
el:'#root',
data:{
  removelines: [
  {value:'a'},
  {value:'b'}
  ]

},

methods:{
 insert:function(){
     let vueIn = this; 

     axios.post('/vue', {removelines: vueIn.removelines.value}).then(
       function(response){
         vueIn.removelines = response.data.removelines.value;
       }
     ).catch(function(error){ console.log(error.message); });
   }
}

});
Run Code Online (Sandbox Code Playgroud)

html代码在这里:

<div class="card-block">
    <div class="btn-group" data-toggle="buttons">
        <label class="btn btn-warning active">
            <input  v-model="removelines" name="removelines" type="radio" class ="cheker" autocomplete="off" v-bind:value="a" checked>
            Yes
        </label>
        <label class="btn btn-warning">
            <input v-model="removelines" name="removelines" type="radio" class ="cheker" v-bind:value="b">
            No
        </label>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

cho*_*sia 9

请检查这个工作样本。

new Vue({
  el: '#root',
  data: {
    removelines: 'b'
  }
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://unpkg.com/vue@2.4.2/dist/vue.js"></script>
<div id="root">
<div class="card-block">
  {{ removelines }}
    <div class="btn-group" data-toggle="buttons">
        <label class="btn btn-warning active">
            <input  v-model="removelines" name="removelines" type="radio" class ="cheker" autocomplete="off" v-bind:value="'a'" checked>
            Yes
        </label>
        <label class="btn btn-warning">
            <input v-model="removelines" name="removelines" type="radio" class ="cheker" v-bind:value="'b'">
            No
        </label>
    </div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

  • 或者更简单的 `value="a"` 也可以 (2认同)