I am working on a timeline that allows the user to take notes on a customer. I would like to display the month and the year before the group of notes that belongs to that month.
For example :
February 2016
"Note 4" - 2016-02-15
"Note 3" - 2016-02-05
January 2016
"Note 2" - 2016-01-28
"Note 1" - 2016-01-12
As I use VueJS to display my notes, I wanted to test each note to check if the month was different from the month saved in a variable called "currentMonth". So I used a v-if in my display to check the value with a function called "isNewMonth" :
<div v-for="note in notes | orderBy 'date' -1" >
<div v-if="isNewMonth(note)"><% currentMonth %></div>
<div style="background-color: #<% note.type.color %>; margin-bottom: 10px; border-left: solid #<% note.type.border_color %> 5px; padding-left: 5px;">
<p class="noteMessage"><% note.message %><p>
<p class="noteInfos">Par <% note.author %> le <% note.date %></p>
</div>
</div>
And the function isNewMonth :
isNewMonth: function(note) {
var noteMonth = parseInt(note.date.split("-")[1]);
if(this.currentMonth != noteMonth)
{
this.$set('currentMonth', noteMonth);
return true;
}
else
{
return false;
}
}
I have an issue with the line "this.$set('currentMonth', noteMonth);". When I add this line, I am stuck in an endless loop. Whenever I remove this line everything is fine (but it always display the month before each note).
Do you know a way to solve my issue ?