PLEASE HELP ME!!!!!
When my application starts i run an ajax to get all my feeds. These are objects that I then store in my vue variable which is an array.
props:['id'],
data(){
return {
feedData: []
}
},
created(){
axios.get('/feeds/'+this.id).then(response =>{
this.feedData = response.data.data;
});
}
After that when the user types and sends a new post i store the new post in the database and then emit an event to capture the new post from the database. The function for this is in my methods.
methods: {
captureFeed: function (feedId) {
const vm = this;
axios.get('/feeds/'+this.id+'/'+feedId).then(response =>{
vm.feedData.unshift(response.data);
console.log(response.data);
});
}
},
The weird thing is that when i successfully get the new feed i just created and try to add it to the array of feeds using unshift for some reason the very first post of the array is duplicated and i never get to see the new post until i refresh the page. When i check the console log, i can see that i got the new feed. The funny thing is that when i use
vm.feedData.push(response.data);
it works just fine, but the post is at the very bottom which is not what i want!
i have images to show:
first post:
second post:
<template> <div class = "col-xs-12 col-md-5 mt-m pr-sm pl-sm"> <timeline-headline></timeline-headline> <div class="panel panel-default"> <div class="panel-body"> <feed-constructor :timeline-id = "id" @newFeedSent = "captureFeed"></feed-constructor> <feed v-for = "feed in feedData" :feedContent="feed"></feed> </div> </div> </div> </template>keyin on thefeedthat you are looping over.:key="feed.id"wherefeed.idis some unique value for each feed.<feed v-for = "feed in feedData" :id="'feed-'+feed.id" :feedContent="feed"></feed>not sure how to use the dynamic key or dynamic feed id to fix this, trying to figure it out