<script>
import { mapGetters, mapActions } from 'vuex'
export default {
computed: {
...mapGetters ({
products: 'cartProducts',
checkoutStatus: 'checkoutStatus'
}),
total () {
return this.products.reduce(( total, p) => {
return total + p.price * p.quantity
}, 0)
}
},
methods: {
...mapActions([
'addToCart',
'removeFromCart',
]),
checkout (products) {
this.$store.dispatch('checkout', products)
}
}
}
</script>
client?cd17:119 ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/pages/CartPage.vue
Module parse failed: C:\OpenServer\domains\pizzaStore\node_modules\babel-loader\lib\index.js!C:\OpenServer\domains\pizzaStore\node_modules\vue-loader\lib\selector.js?type=script&index=0!C:\OpenServer\domains\pizzaStore\src\pages\CartPage.vue Unexpected token (36:8)
You may need an appropriate loader to handle this file type.
| export default {
| computed: {
| ...mapGetters({
| products: 'cartProducts',
| checkoutStatus: 'checkoutStatus'
@ ./src/pages/CartPage.vue 7:2-105
@ ./src/router.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
<template>
<ul>
<li class="product product-item" v-for="p in products">
<div unit-left>
<!--<img :src="'/dist/' + p.picture" class="product-picture">-->
</div>
<div class="unit-body">
<h2 class="product-name">{{p.title}}</h2>
<p class="product-description">{{p.description}}</p>
</div>
<div unit-right>
<span>{{p.price}}</span>
<button class="add-button" @click="addToCart(p)" v-if="qtyInCart == 0">Заказать</button>
<div v-else>
<button class="inc" @click="addToCart(p)">+</button>
{{qtyInCart(p)}}
<button class="dec" @click="removeFromCart(p)">-</button>
</div>
</div>
</li>
</ul>
</template>
<script>
import { mapGetters, mapActions } from 'vuex'
export default {
computed: mapGetters({
products: 'allProducts',
qtyInCart: 'qtyInCart'
}),
methods: mapActions([
'addToCart',
'removeFromCart',
'qtyInCart'
]),
created () {
this.$store.dispatch('getAllProducts')
}
}
</script>
единственный момент остался ...ссылки на главной не совпадают при первом посещении страницы
когда заходишь первый раз на localhost:3000
функция определяет localhost:3000/index.html
window.location.href localhost:3000
соответственно класс не приминяется