# Setup Vuex
# Run in console
npm install --save vuex
1
# app.js
import Vue from 'vue';
import Vuex from 'vuex'; // 1. import Vuex
import App from './components/App';
Vue.use(Vuex); // 2. setup Vuex
import storeData from './store/index';
const store = new Vuex.Store(storeData);
const app = new Vue({
el: '#app',
components: {
App
},
store // 3. attach store to Vue instance
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# store/index.js
export default {
state: {
message: 'VueX store is working!'
},
mutations: {},
actions: {}
};
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
More info: