Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add vue instance for vuex module? #226

Closed
serjo96 opened this issue Feb 5, 2020 · 1 comment
Closed

How to add vue instance for vuex module? #226

serjo96 opened this issue Feb 5, 2020 · 1 comment

Comments

@serjo96
Copy link

serjo96 commented Feb 5, 2020

Sometimes in store need use vue/nuxt global plugins (like $axios with my config or $auth ).
But this in vuex-module-decorators will be set only on current class module, without vue class inheritance .

How I can do that?

In nuxt, I was able to add this plugins in the my nuxt plugin, calling my module class, and passing context or necessary plugins to the constructor, but it looks like a bicycle

@fabianogaldino
Copy link

fabianogaldino commented Feb 13, 2020

I got two alternatives:

  1. Use prototype from Vue
    Problem that vscode will not auto complement
// import vuexModule
import Vue from 'vue';

class Some extends VuexModule {
 @Action
  public teste (id: number) {
   console.log(Vue.prototype.$sessionStorage);
 }
}
  1. Create property vue and type
    Problem is creating a property just to access the vue instance
// import vuexModule
import Vue from 'vue';

class Some extends VuexModule {
 vue: Vue = Vue.prototype;

 @Action
  public teste (id: number) {
   console.log(this.vue.$sessionStorage);
 }
}

I have no idea if this is how we should use it, because I'm new to vue and typescript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants