I have not been able to get the getters from Pinia integrate correclty into my vue3 project.
So i have a index.js, getters.js and the file file where i want to fetch the getter test.js
my index,js looks like this:
import * as actions from './actions'
import * as getters from './getters'
export const usevwoStore = defineStore('vwoStore', {
state: () => {
return {
groups:[],
}
},
actions: actions.actions,
getters: getters.getters
})
if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(usevwoStore, import.meta.hot))
/*import.meta.hot.accept((newModule) => {
if (newModule) {
console.log('updated: count is now ', newModule.count)
}
})*/
}
export default usevwoStore
my getters.js looks like this:
// import { aanwezighedenSecundairHelperService } from './../../services/aanwezigheden-secundair.service.js'
import { useGlobalStore } from '@/store/store.js';
import { toRaw } from "vue";
import { usevwoStore } from './index.js';
import { restServ } from '@/services/rest.service.js';
import router from '@/router/router.js'
const dateOperations = dateOperationsMix.methods
export const getters = {
getgroups(){
return this.usevwoStore.groups
// console.log('sdfsd')
}
}
and finally where i want to fetch the getters is my test.js file
import { mapStores, mapWritableState, mapState } from 'pinia'
import { useGlobalStore } from '@/store/store.js'
import { usevwoStore } from '../../store/index.js'
import { toRaw } from "vue";
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { storeToRefs } from 'pinia'
export default {
name: "test",
setup() {
const myStoreActions = toRaw(useGlobalStore())
const myStoreState = useGlobalStore()
const vwoStoreState = usevwoStore()
const vwoStoreGetters = storeToRefs(usevwoStore())
const route = useRoute();
const currentRoute = computed(() => route.path)
return { myStoreActions, myStoreState,vwoStoreActions,vwoStoreState,route, currentRoute,vwoStoreGetters }
},
data () {
return {}
},
computed: {
groups: {
get: function () {
**return this.vwoStoreGetters.getgroups;**
},
set: function () {
return this.vwoStoreGetters.getgroups;
}
}
....
i am always getting this.vwoStoreGetters.getgroups undefined..is teh logic correct what i am using? Does it have to do with the computed property?
Thanks guys!