-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Hello! I am using nuxt and I can't seem to access my plugins on my action method body, am i doing something wrong??
I currently have my state set up like this:
store/index.ts
import Vuex from 'vuex';
import { extractVuexModule } from 'vuex-class-component';
import { UserStore } from '~/store/user';
export const modules = {
...extractVuexModule(UserStore),
};
store/user.ts
import { Context } from '@nuxt/types';
import { action, createModule } from 'vuex-class-component';
import { IUser } from '~/types/modules/user/userTypes';
const UserModule = createModule({
namespaced: 'user',
strict: false,
target: 'nuxt',
});
export class UserStore extends UserModule {
loggedUser?: IUser = undefined;
@action async fetchLoggedUser() {
console.log(this);
}
}
plugin/storeProxies.ts
import { Plugin } from '@nuxt/types';
import { createProxy } from 'vuex-class-component';
import { UserStore } from '~/store/user';
const storeProxies: Plugin = (context, inject) => {
const vxm = {
user: createProxy(context.store, UserStore),
};
inject('vueStore', { ...vxm });
};
export default storeProxies;
The problem is that when i call await this.$vueStore.user.fetchLoggedUser();
on my component, i can't seem to find the app. When i access the this
i can access the $store
but inside of it i cannot find the context. I need it to make a api call to fetch my user.
Normally i would do something like
@action async fetchLoggedUser() {
const user = this.$api.auth.fetchUser();
etc...
}
Am i missing something?? Thanks!
Metadata
Metadata
Assignees
Labels
No labels