|
|
|
|
@ -25,7 +25,7 @@
|
|
|
|
|
<p class="cart-empty">Корзина пуста</p>
|
|
|
|
|
<p class="cart-empty">Попробуйте перейти на страницу образца</p>
|
|
|
|
|
<p v-if="isItemPath" class="cart-empty">
|
|
|
|
|
и <va-button>Добавить в корзину</va-button>
|
|
|
|
|
и <va-button @click="addToCart">Добавить в корзину</va-button>
|
|
|
|
|
</p>
|
|
|
|
|
</va-card-content>
|
|
|
|
|
</va-card>
|
|
|
|
|
@ -45,9 +45,25 @@
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
name: "navbar",
|
|
|
|
|
methods: {
|
|
|
|
|
addToCart() {
|
|
|
|
|
fetch(`/api/v1/item/${this.$route.params.id}`)
|
|
|
|
|
.then(res => res.json())
|
|
|
|
|
.then(data => localStorage.setItem("cart", JSON.stringify(
|
|
|
|
|
// check if we have anything in this.itemsInCart or create empty
|
|
|
|
|
// then create new array with newly fetched data in it
|
|
|
|
|
[...this.itemsInCart ? this.itemsInCart : [], data]
|
|
|
|
|
)))
|
|
|
|
|
.catch((e) => console.log(e));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
isItemPath() {
|
|
|
|
|
return this.$route.name === "item-details";
|
|
|
|
|
},
|
|
|
|
|
itemsInCart() {
|
|
|
|
|
return JSON.parse(localStorage.getItem("cart"))
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|