V
V
Valery V.2019-03-11 21:52:59
Vue.js
Valery V., 2019-03-11 21:52:59

How to bind input via v-model in a loop?

Good afternoon!

<template v-for="(item, index) in items">
  <input type="checkbox" v-model="item.checked" />
</template>

How to properly bind v-model value?
computed: {
    items: {
        get () {
          return  this.$store.state['options'].items;
        },
        set (value) { 
          this.$store.commit('options/SET_ITEMS_PROPERTY', value);
        }
      }
}

But for some reason the change of input.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-03-12
@OlegOleg1980

The v-model should be an array, not the state of a particular checkbox; in addition, checkboxes should specify values. There is an example in the documentation . Accordingly, your code can (but not the fact that you need to) rewrite something like this , for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question