1

https://jsfiddle.net/50wL7mdz/359940/

<script src="https://unpkg.com/vue"></script>

<div id="app">
  <label>                   
    <input 
    type="checkbox"
            name="demo"
    :checked="isChecked"
            @input="someMeth('A')" 
    value="A"/> 
    A
 </label>
 <label>
    <input
    type="radio" 
    name="demo"
    :checked="isChecked"
    @input="someMeth('B')" 
    value="B"/> 
    B
 </label>
 <div>
  {{somedata}}
 </div>
</div>

Clicking on input(checkbox or radio) does not toggle its status.

Remove either :checked or @input would solved the problem.

but I need them both.

@click does the same thing.

1 Answer 1

3

in vue.js,checkbox's value is bind using v-model.

new Vue({
  el: '#app',
  data: {
    checktype: 'checkbox',
    somedata: [],
    isChecked: false,
    isChecked2: false,
  },
  methods: {
  	someMeth(val) {
    		this.somedata.push(val)
    }
  }
})
<script src="https://unpkg.com/vue"></script>

<div id="app">
    <label>
        <input 
            :type="checktype"
            :name="demo"
            v-model="isChecked"
            @input="someMeth('A')" 
            value="A"/>	
            A
    </label>
    <lable>  
        <input
            :type="checktype" 
            :name="demo"
            v-model="isChecked2"
            @input="someMeth('B')" 
            value="B"/>	
            B
    </lable>
    <div>
        {{somedata}}
    </div>
</div>

Sign up to request clarification or add additional context in comments.

4 Comments

I'm using :checked because it's 'pre-checked' status from a method. I have other situation using :checked and v-model together, like a radio, it's working fine.
If you use v-model, you don't need :checked coz v-model does for checking status @chriszhxi
v-model is 2-way binding, :checked it's just the initial status, this status does not change.
This is definitely the answer @chriszhxi, please make sure you're following the implementation example Kaicui provided

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.