[Vuejs]-Vue.js dynamically adding to a list of components

0👍

Your issue is caused by the fact that you both modify the state, and use the state from the same method.

showDate(data) {
  this.currentDataMonth = helperfunctionsgetDate_format_month_year(data) // set of the state
  if (this.currentDataMonth != this.currentmonth) { // get of the state
    this.currentmonth = this.currentDataMonth
    return "<h2>" + this.currentmonth + "</h2>"
  } else {
    return ""
  }

Since you directly use those variables inside your function, make them local to the function

showDate(data) {
  const currentDataMonth = helperfunctionsgetDate_format_month_year(data)
  if (currentDataMonth != undefined) {
    const currentmonth = currentDataMonth
    return "<h2>" + currentmonth + "</h2>"
  } else {
    return ""
  }

Since the purpose of the code is to list every month under its own heading, you should do that using a computed function to return a list of data per month, and use 2 loops to loop over that

Leave a comment