Introducing Vuex Chapter 8
After that, run the following command:
$ npm run dev
The preceding command will spin up your server and open a port in localhost:8080.
Installing Vuex
The next step is to install vuex. To do that, run the following command:
$ npm install --save vuex
Setting up Vuex
Now, let's create a store folder to manage the vuex in our application.
Creating a store file
In the src directory, create a store folder and store.js file. Then, add the following
to the store.js file:
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
In the preceding code block, the line Vue.use(Vuex) imports the Vuex library. Without
this, we will not be able to use any of the vuex functionalities. Now, let's build a store
object.
State
In the same store.js file, add the following lines of code:
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const state = {
count: 0