Skip to content

Vue Composition API: Getters

Mike Lyttle edited this page May 11, 2023 · 3 revisions

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

Clone this wiki locally