File tree 1 file changed +59
-56
lines changed
1 file changed +59
-56
lines changed Original file line number Diff line number Diff line change @@ -3,84 +3,87 @@ import Vuex from "vuex";
3
3
4
4
Vue . use ( Vuex ) ;
5
5
6
- // Exercise 5? Kill the counter store and use the products store below!
6
+
7
+ const productList = [ {
8
+ name : "Vue Socks" ,
9
+ brand : "Vue" ,
10
+ price : 5 ,
11
+ variants : [
12
+ { id : 1 , color : "green" } ,
13
+ { id : 2 , color : "blue" }
14
+ ] ,
15
+ inventory : 3 ,
16
+ reviews : [ ]
17
+ } ,
18
+ {
19
+ name : "Angular Socks" ,
20
+ brand : "angular" ,
21
+ price : 15 ,
22
+ variants : [
23
+ { id : 1 , color : "red" } ,
24
+ { id : 2 , color : "blue" }
25
+ ] ,
26
+ inventory : 3 ,
27
+ reviews : [ ]
28
+ } ,
29
+ {
30
+ name : "npm Socks" ,
31
+ brand : "npm" ,
32
+ price : 3 ,
33
+ variants : [
34
+ { id : 1 , color : "red" } ,
35
+ ] ,
36
+ inventory : 3 ,
37
+ reviews : [ ]
38
+ } ] ;
39
+
7
40
8
41
export default new Vuex . Store ( {
9
- // ~ component.data
10
42
state : {
11
- count : 0
43
+ premium : true ,
44
+ cart : [ ] ,
45
+ products : productList
12
46
} ,
13
47
14
- // ~ component.methods
15
- actions : { } ,
48
+ actions : {
16
49
17
- // ~ component.computed
50
+ } ,
18
51
getters : {
19
- countAlias ( state ) {
20
- return state . count ;
21
- }
52
+
22
53
} ,
23
54
24
- // ~ redux.reducers
25
55
mutations : {
26
- increment ( state ) {
27
- state . count ++ ;
28
- } ,
29
- decrement ( state ) {
30
- state . count -- ;
56
+ addToCart ( state , product ) {
57
+ const cart = state . cart as any ;
58
+ cart . push ( product ) ;
31
59
}
32
60
} ,
33
61
} ) ;
34
62
35
63
36
- // const productList = [{
37
- // name: "Vue Socks",
38
- // brand: "Vue",
39
- // price: 5,
40
- // variants: [
41
- // {id: 1, color: "green"},
42
- // {id: 2, color: "blue"}
43
- // ],
44
- // inventory: 3,
45
- // reviews: []
46
- // },
47
- // {
48
- // name: "Angular Socks",
49
- // brand: "angular",
50
- // price: 15,
51
- // variants: [
52
- // {id: 1, color: "red"},
53
- // {id: 2, color: "blue"}
54
- // ],
55
- // inventory: 3,
56
- // reviews: []
57
- // },
58
- // {
59
- // name: "npm Socks",
60
- // brand: "npm",
61
- // price: 3,
62
- // variants: [
63
- // {id: 1, color: "red"},
64
- // ],
65
- // inventory: 3,
66
- // reviews: []
67
- // }];
68
-
69
-
70
64
// export default new Vuex.Store({
65
+ // // ~ component.data
71
66
// state: {
72
- // premium: true,
73
- // cart: [],
74
- // products: productList
67
+ // count: 0
75
68
// },
76
69
70
+ // // ~ component.methods
77
71
// actions: {},
78
- // getters: {},
79
72
73
+ // // ~ component.computed
74
+ // getters: {
75
+ // countAlias(state) {
76
+ // return state.count;
77
+ // }
78
+ // },
79
+
80
+ // // ~ redux.reducers
80
81
// mutations: {
81
- // addToCart(state, product) {
82
- // const cart = state.cart as any;
83
- // cart.push(product);
82
+ // increment(state) {
83
+ // state.count++;
84
+ // },
85
+ // decrement(state) {
86
+ // state.count--;
84
87
// }
85
88
// },
86
89
// });
You can’t perform that action at this time.
0 commit comments