[Vuejs]-In vueJS I want to get actual value of the checkbox but I just get true or undefined

3👍

You need to add true-value and false-value. See the docs: Checkbox:

<input
  type="checkbox"
  v-model="toggle"
  true-value="yes"
  false-value="no"
>

// when checked:
vm.toggle === 'yes'
// when unchecked:
vm.toggle === 'no'

1👍

For a single checkbox you can use true-value and false-value attributes; for multiple checkboxes, use an array for the v-model:

var app = new Vue({
  el: '#app',
  data: {
    foo: ["One"]
  }
})
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<div id="app">
  <input type="checkbox" name="Foo" v-model="foo" value="One"> One<br>
  <input type="checkbox" name="Foo" v-model="foo" value="Two"> Two<br>
  v-model value is: {{foo}}
</div>

Leave a comment