Good evening, I have searched for the problem I'm having for quite some time and haven't seen an answer or post close enough to extract useful help.
I am retrieving some dates from Firebase that I would like to populate into some ui elements in my Vue app. the ultimate goal is to get each date that comes from Firebase to match with the corresponding month in the Vue app and fill those ui elements. So far, I am having trouble getting the data to show in properly at all without causing an infinite loop warning.
Here is the code so far below:
data() {
return {
dates: [], <---- dates will fill this array from Firebase
months: [
{name: 'Jan', createdOn: [] },
{name: 'Feb', createdOn: [] },
{name: 'Mar', createdOn: [] },
{name: 'Apr', createdOn: [] },
{name: 'May', createdOn: [] },
{name: 'Jun', createdOn: [] },
{name: 'Jul', createdOn: [] },
{name: 'Aug', createdOn: [] },
{name: 'Sept', createdOn: [] },
{name: 'Oct', createdOn: [] },
{name: 'Nov', createdOn: [] },
{name: 'Dec', createdOn: [] },
]
};
},
methods: {
logNewDate() {
let mons = this.months
let dates = this.dates
dates.forEach(date => {
if(!mons[0].createdOn.includes(dates)) {
mons[0].createdOn.push(date.createdOn)
}
})
console.log(mons[0].name, mons[0].createdOn)
},
}
<div v-for="month in months" :key="month.name">
<b-button
class="btn-circle btn-md"
>
{{ month.name }}
</b-button>
</div>
{{ logNewDate() }}
At first the I had the months array as an array or month strings, but this simply caused all the dates in firebase to loop repeatedly for each month creating 5 ui elements each time but no infinite loops initially. I figured the next step was to have an array collection included with the name of the month so that i could store multiple dates from the same month together, so idea with the months property shown above in the data function is to match the incoming data with the proper month name and fill that objects createdOn array with the matching dates.
So far the forEach loop in my logNewDate function will store all the dates that show from Firestore (only 5 right now for testing purposes) but once all five show it loops back through and adds all five dates again over and over. At first I used a for in loop that iterated the dates array and added each date to the createdOn array, but this caused an infinite loop too which makes me think there's a more fundamental issue with my approach in this code.
After some researching around, I tried using a if(mons[0].createdOn.includes(date)) check to only include dates that hadn't shown up yet and no others, but that didn't work. I also tried adding break in the loop with no effect either. the function that retrieves the Firebase data is currently in my created lifecycle method. I'd only like this to happen once for what I'm testing right now. Can someone help me understand what's causing the loop and how to fix it and prevent these errors going forward?
I'd also like to note that I realize hardcoding the array indexes in the forEach loop isnt the best practice. I ultimately want that to be dynamic, equating with the month of the date from Firebase. I hardcoded them in my example for testing purposes.


if(!mons[0].createdOn.includes(dates))is not checking for the thing that's being pushed, so I don't think that will prevent dups.logNewDateis being invoked twice? I don't know Vue.js but I guess it has something to do with the way it renders.