how to bind v-model to a specific array element in vuejs?

10,211

Yes, that is the right way:

var vm = new Vue({
  el: '#vue-instance',
  data: {
    items: ["Item1", "Item2"]
  } 
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.10/vue.min.js"></script>


<div id="vue-instance">
  <input v-model='items[0]'/>  
  <div v-for="item in items">
    {{item}} 
  </div>
</div>
Share:
10,211

Related videos on Youtube

AngeloC
Author by

AngeloC

js beginner

Updated on September 15, 2022

Comments

  • AngeloC
    AngeloC about 1 year

    I would like to bind v-model to a specific array element like following, possible?

    <input v-model='item[1]' />
    

    Thanks