I am currently encountering an issue with my Vue components. I have structured them in a hierarchy where I have a post-index
component displaying all posts, containing a post-view
component for individual posts, and within that, a post-like
component to handle likes and dislikes.
Everything works smoothly until I add a new post using the .unshift()
method. This is when things start to go awry.
For example, everything looks perfect: https://i.sstatic.net/QW50a.png
But as soon as I create a new post: https://i.sstatic.net/YA47E.png
You can see that the like button is incorrectly highlighted, even though it hasn't been liked by the user. After investigating, I discovered that the value for liking or disliking the post is being duplicated from the post below. It seems like the new component is not being created for the new post, but rather added at the bottom. Is there a solution to this problem?
Inside the post-like
component, there is only a data property called like
, which manages the like and dislike functionality.
My assumption is that Vue is re-rendering from the top and adding new components at the bottom. How can I resolve this issue? Please let me know if you need more information on this matter.