davestewart/vue-class-store

Accessing getters and methods externally

Rigidoont opened this issue · 7 comments

Hi! Can getters and methods of a store be accessed from the outside? For example, from a component that uses store:

// vue component

@Component({})
export default class MyComponent extends Vue {

 @Inject() store: MyStore;

 mounted() {
  console.log(this.store.filtered); // always undefined :(
 }

}
// store

@VueClassStore
export class MyStore {

 get filtered(): string[] {
  return ['a', 'b'];
 }

}

Hello.

That's strange. It should work.

What happens if you inspect the component in the Vue DevTools?

Also, what is your actual import in the store file?

When I inspect the component I see the store with only the data property, no computed.

An example from a real component in my project:
chrome_vRH6KoUwWy

In the store there is a filtered getter, but no computed property in inspector is present.

Import in the store file looks exactly like this:
import VueClassStore from 'vue-class-store';

What happens if you don't use class components?

Also, what happens if you set the store as a window property in your main file, and reference the computer property from there (just to debug) ?

In plain vue, without class components the same thing happens.

I'm using nuxt so I don't really have a main file. I've created a simple plugin and put it on the top so it would run sooner than others, computed property is still empty.

That's really strange, and I'm sorry it's happening; it must be frustrating.

Is there some way you could share a simple repo I could look at?

Well the good news is that I resolved the problem. The bad news is that it took me so long...
It seems I had v2.0.0 of the package installed and it refused to be updated for some reason. I completely reinstalled the package and everything works now. Should have started with that.

Thanks a lot for your help, I didn't at all expect such quick responses! Great package!

Good news!

No problem, glad to help, and the package is still quite new so I'm keen to help people where they need it and fix problems that may arise!

I hope you enjoy using the package.

TTFN