/
index.js
60 lines (54 loc) · 1.58 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import OrderPizza from './OrderPizza.vue'
import Vue from 'vue/dist/vue.esm.js'
import Vuex from 'vuex/dist/vuex.esm.js'
Vue.use(Vuex);
export const store = new Vuex.Store({
state: {
cart: [],
customerid: null
},
mutations: {
CUSTOMERID(state, customerid) {
state.customerid = customerid
},
CART(state, cart) {
state.cart = cart
},
},
getters: {
customerid: state => state.customerid,
cart: state => state.cart,
},
actions: {
updateCart: ({ commit }, { cart }) => {
commit('CART', cart)
},
initState: ({ commit }) => {
import('./kernel')
.then((module) => {
module.onKernelKey('change:customerid', customerid => {
commit('CUSTOMERID', customerid);
});
const customerid = module.getSharedKernel('customerid');
if (customerid != null) {
commit('CUSTOMERID', customerid);
}
module.onKernelKey('change:cart', cart => {
commit('CART', cart);
});
const cart = module.getSharedKernel('cart');
if(cart != null){
commit('CART', cart);
}
});
},
}
})
export const VueApp = (el) => {
const App = new Vue({
template: '<OrderPizza/>',
components: { OrderPizza },
store
})
App.$mount(el);
}