Search code examples
vuejs3vue-composition-apipinia

How do to use Pinia getters in Vue template?


How do I use Pinia getters defined in my store in my component templates? With Vuex, I can do this.$store.getters.getterName(params). Here is my attempt using Pinia.

<script lang="ts">
import { useStore } from "@/store/store";

export default {
  setup() {
    const store = useStore;

    return {
      store,
    };
  },
};
</script>

<template>
<h1>{{ store.getterName(params) }}</h1>
</template>

Solution

  • You forgot to call useStore inside setup.

    export default {
      setup() {
        const store = useStore();
    
        return {
          store,
        };
      },
    };