Let's start by adding Vuex to our project. Follow these steps:
- Open up the Terminal and run the following command to get Vuex added to the project as a dependency:
> npm install vuex
- Now that we have the library installed, we need to add it as a plugin to our app. Go to main.js, import it and add it with the following lines of code. You can place them after the Vue and App import statements:
import Vuex from 'vuex';
Vue.use(Vuex);
const store = new Vuex.store({
// Our global store
});
The store variable will hold all of our global states, including our actions and mutations as well. We'll discuss those in more detail soon. For store to be available to the whole app, we are missing one last step. We need to inject the store variable into our Vue instance.
- Inside main.js still, go to the configuration options for the new Vue instance...