Search code examples
typescriptvue-componentvuex

vuex lazy loaded data


I am using class based component.

I have one data properties which is being used by two different pages.

Now that data needs to be lazy.

i.e. when one page is accessing it then only take that data using ajax. so that second page which tries to access that value from store, it doesn't need to take it another time.

I can surely take one flag, and then bring data based on it. But it would be great, if these can be done in vuex store only.

How this can be achieved knowing that typescript type getter and setter are not available in vuex officially? If this would have been there, then I could use it to get data on getter after checking value of flag.


Solution

  • I was able to get this by using static fields of typescript class.

    As static fields are being shared among components. I used their getter & setter methods instead of vuex store.