Skip to content

Commit 376033c

Browse files
committed
vuex store start
1 parent 56a4aa4 commit 376033c

File tree

1 file changed

+59
-56
lines changed

1 file changed

+59
-56
lines changed

cli-socks/src/store.ts

+59-56
Original file line numberDiff line numberDiff line change
@@ -3,84 +3,87 @@ import Vuex from "vuex";
33

44
Vue.use(Vuex);
55

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+
740

841
export default new Vuex.Store({
9-
// ~ component.data
1042
state: {
11-
count: 0
43+
premium: true,
44+
cart: [],
45+
products: productList
1246
},
1347

14-
// ~ component.methods
15-
actions: {},
48+
actions: {
1649

17-
// ~ component.computed
50+
},
1851
getters: {
19-
countAlias(state) {
20-
return state.count;
21-
}
52+
2253
},
2354

24-
// ~ redux.reducers
2555
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);
3159
}
3260
},
3361
});
3462

3563

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-
7064
// export default new Vuex.Store({
65+
// // ~ component.data
7166
// state: {
72-
// premium: true,
73-
// cart: [],
74-
// products: productList
67+
// count: 0
7568
// },
7669

70+
// // ~ component.methods
7771
// actions: {},
78-
// getters: {},
7972

73+
// // ~ component.computed
74+
// getters: {
75+
// countAlias(state) {
76+
// return state.count;
77+
// }
78+
// },
79+
80+
// // ~ redux.reducers
8081
// 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--;
8487
// }
8588
// },
8689
// });

0 commit comments

Comments
 (0)