Enabling strict mode while developing
When Vuex
is in strict mode, it will throw an error if the single state tree is mutated outside mutation handlers. This is useful when developing to prevent accidental modifications to the state. To enable strict mode, you just need to add strict: true
to the store configuration object:
const store = new Vuex.Store({
// ...
strict: true
});
Strict mode should not be used in production. Strict mode runs a synchronous deep watcher on the state tree for detecting inappropriate mutations, and this can slow down the application. To avoid changing strict to false
each time you want to create a production bundle, you should use a build tool that makes the strict value false
when creating the production bundle. For example, you could use the following snippet in conjunction with webpack:
const store = new Vuex.Store({
// ...
strict: process.env.NODE_ENV !== 'production'
})
In Chapter 3, Implementing Notes App UsingVuex State Management, you will be shown how...