May 18, 2021
Per Djurner

Nullish coalescing operator in Vue templates

The nullish coalescing operator can be really useful when you want to display, for example, "N/A" when a value is null or undefined, but not when it's 0.

<template>
  <p>{{ val ?? 'N/A' }}</p>
</template>

<script>
export default {
  data() {
    return {
      val: 0
    }
  }
}
</script>

Note that you need Vue 3 for this to work in templates.

Home