Vue Composition API: Getters - bcgov/healthgateway GitHub Wiki

Class Component

    slideIndex = 0;
    get isFirstSlide(): boolean {
        return this.slideIndex === 0;
    }

Composition API

import { computed, ref } from "vue";
const slideIndex = ref(0);
const isFirstSlide = computed(() => slideIndex.value === 0);

Notes

  • Since getters are no longer accessed with the this. prefix, be sure to verify that no function parameters share the same names, as a conflict can lead to cryptic bugs.

Documentation