5👍
Personally, I only put things into the Vuex (or Redux) store that will have some impact to the user. Data from the backend, settings/configurations that alter the interface, etc. You should be able to bootstrap your store data on page load so that if the user refreshes, they’re exactly where they were before.
Some configuration options might make sense in the store (particularly if the user can change them somehow). For most things (like app name, app version, etc.), I usually keep them in an environment variable (via the .env
file), and read them in as-needed in my application code. Rather than injecting them into the store, I would opt to generate constants for them so there is no risk of them changing if they are not supposed to. This has a lot of benefits:
- It’s very easy to have different configurations for different environments
- It’s easy to keep your production configuration out of git in the case that it contains sensitive data (e.g. API credentials)
- This data is stored in a clear, concise, and consistent location. It’s easy to see how the data changes over time via source control
- It’s impossible to accidentally modify a variable in state that you didn’t intend to
2👍
As far as I know there is really nothing wrong with storing configuration in Vuex.
Now password and other sensitive information is another thing.
I personally store sensitive info in .env
as :
MONGODB_URI=mongodb://foo:bar@foo.com/foobar
MAILGUN_USER=2342d@34234218b9fd5d4e5dc.mailgun.org
MAILGUN_PASSWORD=4uri62342342
You can also store and export other simple configuration in a js file as:
export default {
app: [
name: 'foo',
path: '../app'
]
}
Anything outside those that you need to manage the state of (change) or access globally can and should be done in vuex.
0👍
Well, to some extent, it could be, but it really depends on what you’re trying to do, Vuex should not be used in the first place in smaller applications, but if you are going for making a medium to large sized application, it is more than just good practice and can make it much easier and the code much cleaner, so, yes, to some extent.