'add comment using v-model inside v-for loop in posts

I'm getting a posts array from a vuex getter and looping through them with v-for to display each post and it's comment then i added an input field and binded it with v-model to get the input value and dispatch an action to send the value to the API

<div class="post-content"  v-for="(post, index) in posts">
   <div class="post-comment">
        <input type="text" class="form-control" placeholder="Add a comment" v-model="comment" @keyup.enter="addComment(post.id)">
   </div>
</div>
<script>
  export default {
    data() {
      return {
        postContent: '',
        comment: ''
      }
    },

    methods: {
      addPost() {
        this.$store.dispatch('addPost', {
          content: this.postContent
        })
        this.postContent = ''
      },
      addComment(postID, index) {
        this.$store.dispatch('addComment', {
          body: this.comment,
          post_id: postID
        })
      }
    },

    created(){
        this.$store.dispatch( 'loadFeed' )
    },

    computed: {
        postsLoadStatus(){
        return this.$store.getters.getPostsLoadStatus
        },

        posts(){
        return this.$store.getters.getFeed
        }
    },
  }
</script>

but when i set the v-model to a data property and try to type something in the input it's assigned on all posts so what's the right way to grab the comment data



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source