Vuex is my preferred way to manage state within Vue. Vuex is better structured using modules to make your code more readable and maintainable.
Create a Vue app as you will always do using
vue create myApp. Do a
cd myApp && vue add vuex if you have not selected Vuex at the very beginning.
store folder in the
src folder of the Vue project. This will be the root of all Vuex. Create an
index file to initiate store.
Now start adding modules. Create a file called
user.js and another file called
account.js in the
store folder. These files can have the basic structure of a store -
Include the modules within the main
index store file.
You can refer modules of Vuex as easily in any Vue view or component.
You should consider adding modules for any project to retain your sanity. Although a single file can get the job done, the trauma of maintaining such code will be too great for mere words.