[Vuejs]-How to handle different input values created with v-for

2πŸ‘

βœ…

In a larger/production app, I would probably make each user field its own component (or two, one for the tweet and one for the reply, both orchestrated by this parent).

in this case, you can use the key as the array index for replies and get only the relevant information. See the updated fiddle.

in template:

<input v-bind:id="'reply-'+key" v-model="replies[key]" type="text">
<button v-on:click="reply(replies, tweet.user, key)">Reply</button>

in methods:

reply(reply, user, key) {
  alert("You replied\n" + reply[key] + "\nto " + user);
},

https://jsfiddle.net/n60d4qos/9/

πŸ‘€LShapz

Leave a comment