Recently, I came across a code snippet that caught my attention:
<comment-form @created="add"></comment-form>
<div v-for="(comment, index) in items" :key="comment.id">
<comment :data="comment"></comment>
</div>
Within my mixin, I have a method that is triggered when the event created
occurs:
methods: {
add(item) {
this.items.push(item);
this.$emit('added');
}
}
After adding a new comment, it always appears at the bottom. I have been trying to figure out how to reverse this order so that newly added comments show up at the top of the list instead of the bottom.
I attempted to use the following:
v-for="(comment, index) in items.slice().reverse()"
Unfortunately, this approach did not work as expected, and the comments continued to display from the top to the bottom.