Skip to content

Commit 3dd8dda

Browse files
committed
Vuex: counter page
1 parent 9cc8775 commit 3dd8dda

File tree

7 files changed

+97
-13
lines changed

7 files changed

+97
-13
lines changed

Exercises.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Exercises
2+
=========
3+
4+
Remove from cart
5+
----------------
6+
Add a button to remove socks from the Cart.
7+
- Disable the button when the color is not present in the cart.
8+
9+
10+
Inventory per color
11+
-------------------
12+
Keep track of inventory per color.
13+
- Add to cart should only be enabled when there are socks in that color left in the inventory.
14+
15+
16+
Reviews
17+
-------
18+
- Add validation: name is required
19+
- Add validation: Must accept the terms
20+
- Display all reviews already submitted
21+
22+
23+
New page: Cart contents
24+
-----------------------
25+
Add a new router link `/cart` and... display the cart contents.
26+
- Create a new `CartProduct` component to display the information. (with an image?)
27+
- Add a product price.
28+
- Allow to order more/less of a product in the Cart
29+
- Calculate the total Cart cost. (with shipping costs?)
30+
31+
32+
Vuex
33+
----
34+
- Put the `Product.vue` product properties in the store.
35+
- On the main page, loop over the products and display them.

Vuex-Flow.png

7.92 KB
Loading

cli-socks/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<div class="links">
77
<router-link to="/">Home</router-link> |
8-
<router-link to="/about">About</router-link>
8+
<router-link to="/counter" title="Vuex example">Counter</router-link>
99
</div>
1010
</div>
1111

cli-socks/src/router.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export default new Router({
1414
component: Home
1515
},
1616
{
17-
path: "/about",
18-
name: "about",
17+
path: "/counter",
18+
name: "Vuex Counter",
1919
// route level code-splitting
20-
// this generates a separate chunk (about.[hash].js) for this route
20+
// this generates a separate chunk (counter.[hash].js) for this route
2121
// which is lazy-loaded when the route is visited.
2222
component: () =>
23-
import(/* webpackChunkName: "about" */ "./views/About.vue")
23+
import(/* webpackChunkName: "counter" */ "./views/Counter.vue")
2424
}
2525
]
2626
});

cli-socks/src/store.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,24 @@ import Vuex from "vuex";
44
Vue.use(Vuex);
55

66
export default new Vuex.Store({
7-
state: {},
8-
mutations: {},
9-
actions: {}
7+
// ~ component.data
8+
state: {
9+
count: 0
10+
},
11+
12+
// ~ component.methods
13+
actions: {},
14+
15+
// ~ component.computed
16+
getters: {},
17+
18+
// ~ redux.actions
19+
mutations: {
20+
increment(state) {
21+
state.count++;
22+
},
23+
decrement(state) {
24+
state.count--;
25+
}
26+
},
1027
});

cli-socks/src/views/About.vue

Lines changed: 0 additions & 5 deletions
This file was deleted.

cli-socks/src/views/Counter.vue

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<template>
2+
<div class="counter">
3+
<h1>Vuex Counter</h1>
4+
<p>{{ count }}</p>
5+
<p>
6+
<button @click="increment">+</button>
7+
<button @click="decrement">-</button>
8+
</p>
9+
</div>
10+
</template>
11+
12+
<script lang="ts">
13+
import { Component, Vue } from "vue-property-decorator";
14+
import { mapState, mapGetters } from 'vuex';
15+
16+
@Component
17+
export default class Counter extends Vue {
18+
get count(): number {
19+
return this.$store.state.count;
20+
}
21+
22+
increment(): void {
23+
this.$store.commit('increment');
24+
}
25+
26+
decrement(): void {
27+
this.$store.commit('decrement');
28+
}
29+
}
30+
</script>
31+
32+
33+
<style scoped lang="scss">
34+
.counter {
35+
padding-left: 25px;
36+
}
37+
</style>

0 commit comments

Comments
 (0)