[Vuejs]-Class conditional with vue js

0πŸ‘

I don’t know if I understood you properly, but this is my suggestion:

//div in v-fored td
:class="dynamicClass(dayDate)"

// script

computed: {
  dynamicClass () {
    return (day) => {
      let event = this.events.find(ev => ev.event_date === day);
      return event.user_id !== 0 ? 'event_selected':'event_free'
    }
  } 
}

0πŸ‘

the solution was to add a condition that the typeof my object should not be undefined and iused the idea in the answer of Eggon

Leave a comment