Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (30 sloc) 775 Bytes
<template>
<button
class="o-button o-button--secondary"
@click="toggleShoppingCartState(product)"
>
{{ label }}
</button>
</template>
<script>
import store from "../store";
export default {
computed: {
label: function() {
return store.getters.getProductIsInShoppingCart(this.product)
? "Remove from cart"
: "Add to cart";
}
},
props: ["product"],
methods: {
toggleShoppingCartState: function(product) {
store.commit("toggleShoppingCartState", product);
let message = store.getters.getProductIsInShoppingCart(this.product)
? `${product.title} has been added to from cart`
: `${product.title} has been removed from cart`;
this.$announcer.set(message);
}
}
};
</script>
You can’t perform that action at this time.