1

I have below checkboxes

<div v-for="skill in skills">
  <div class="skill"> 
      <input type="checkbox" value="skill.skill_name" v-model="checkedSkills" @click="getVal()"/>
                <b>{{ skill.skill_name }}</b>
  </div>
</div>

If I click one checkbox all checkboxes become checked.

1 Answer 1

1

First, you should be binding the value attribute, eg

<input type="checkbox"
       :value="skill.skill_name" 
       v-model="checkedSkills" 
       @click="getVal" />

Otherwise, all your checkboxes have the same, static value of "skill.skill_name".

Second, make sure checkedSkills is an array and not a single, scalar value (see https://v2.vuejs.org/v2/guide/forms.html#Checkbox)

data: { // use a function if it's a component
  skills: [], // or whatever initial data you have
  checkedSkills: [] // this is the important bit
}

Demo ~ https://jsfiddle.net/j4wumg5f/

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

2 Comments

Thanks @Phil for your reply. How can I use v-model="checkedSkills" ?
I'm sorry but I don't understand your question

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.