[Vuejs]-Boolean function: check whether first expression is executed or the second

0👍

These conditions can be expressed in the markup…

{{ p1 > 6 ? 'greater than 6' : (p1 === 5 ? 'equal to 5' : 'neither' ) }}

Or, the way I prefer, in a method that’s understood to produce a string for the markup…

<!-- in the markup -->
{{ theThingAboutP(p1) }}

// in methods: {}
theThingAboutP(p1) {
  if (p1>6) return 'greater than 6';
  if (p1===5) return 'equal to 5';
  return 'neither';
}

Leave a comment