Preparation for using Vuex

Add vuex

1
yarn add -D vuex

Make ./store/index.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// ./store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const state = {}
const getters = {}
const actions = {}
const mutations = {}
export default new Vuex.Store({
state,
getters,
actions,
mutations
})

Modify ./main.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// ./main.js
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store' // added
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
store, // added
components: { App },
template: '<App/>'
})