11

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

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

Thanks

1 Answer 1

16

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>

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

Comments

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.