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

Separate instances of Vuex store clash each other when working across separate Vue instances #1462

Closed
guywithdoubts opened this Issue Nov 28, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@guywithdoubts

guywithdoubts commented Nov 28, 2018

Version

3.0.1

Reproduction link

https://jsfiddle.net/9rLp5t4s/

Steps to reproduce

I am currently learning/prototyping vue.js and vuex (using plain js, at the moment). I am trying to accomplish following:

1)create multiple vue instances having their own vuex stores independent to each other. Right now, I am storing only ajax status/progress in vuex store and improve it gradually.
2)vue instances can come from same vue definition (template, methods etc.), but need to work with different vuex store instances.
3)vuex stores should not know about each other (no clashes) and should only work exclusively with their respective vue instance counter parts.

I almost achieved the above as shown in fiddle:

Theoritically, we can just create one class out of app.js and app2.js (identical code). But, just to test/troubleshoot things, I separated them.

I am able to pull data and everything seems working fine. If I refresh button in second instance the console log shows perfectly. If I refresh button in first instance it clashes with the vuex store in second instance

What is expected?

the vue instance should not clash with other vuex stores not related to it

What is actually happening?

first vue instance clashes with vuex store in second instance


more information here: https://stackoverflow.com/questions/53522844/separate-instances-of-vuex-store-clash-each-other-when-working-across-separate-v

@ktsn

This comment has been minimized.

Member

ktsn commented Dec 2, 2018

Because you are registering your two TodosList components to the exact same Vue object. Even though you assign it to different variables (in your code app.Vue and app2.Vue), there are pointing the same object. Then the refresh button always call the second getTodosAsync function.

Note that you should not create multiple Vuex instance in the same page since it assumes there is only store instance. Please use module (with namespaced: true option) instead when you want to separate your state and logic.
https://vuex.vuejs.org/guide/modules.html

@ktsn ktsn closed this Dec 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment