-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
/
Copy pathShoppingCart.vue
42 lines (37 loc) · 1.1 KB
/
ShoppingCart.vue
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
<template>
<div class="cart">
<h2>Your Cart</h2>
<p v-show="!products.length">
<i>Please add some products to cart.</i>
</p>
<ul>
<li v-for="product in products" :key="product.id">
{{ product.title }} - {{ currency(product.price) }} x {{ product.quantity }}
</li>
</ul>
<p>Total: {{ currency(total) }}</p>
<p><button :disabled="!products.length" @click="checkout(products)">Checkout</button></p>
<p v-show="checkoutStatus">Checkout {{ checkoutStatus }}.</p>
</div>
</template>
<script>
import { computed } from 'vue'
import { useStore } from 'vuex'
import { currency } from '../currency'
export default {
setup () {
const store = useStore()
const checkoutStatus = computed(() => store.state.cart.checkoutStatus)
const products = computed(() => store.getters['cart/cartProducts'])
const total = computed(() => store.getters['cart/cartTotalPrice'])
const checkout = (products) => store.dispatch('cart/checkout', products)
return {
currency,
checkoutStatus,
products,
total,
checkout
}
}
}
</script>