aboutsummaryrefslogblamecommitdiff
path: root/client/src/views/Product.vue
blob: d1fde29b4358aa6964e63e48456c1afe6e528cec (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
          




                                                  
                                                                    



                                 





                                                                                                     
                                                                    
                                                                                                                  



                






                  
                   
                                                               
    









                                                           


            


                                      
                                                                  



         
<template>
  <div class="mt-5 d-flex justify-content-center">
    <div class="card col-md-8">
      <div class="row g-0">

        <div class="col-md-6">
          <img :src="curProductImg" class="img-fluid rounded-start">
        </div>

        <div class="col-md-6">
          <div class="card-body">
            <h3 class="card-title" v-text="curProduct.name"></h3>
            <h6 class="card-subtitle mb-2 text-muted">Price: ${{ curProduct.price }}</h6>
            <p class="card-text" v-text="curProduct.description"></p>
            <p class="card-text"><small class="text-muted">Amount: {{curProductQuantity}}</small></p>
          </div>
          <div class="card-footer">
            <div class="btn btn-dark" @click="buy">Add to cart</div>
            <div class="btn btn-secondary ms-3" v-show="curProductQuantity" @click="remove">Remove from cart</div>
          </div>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Product',
  async mounted() {
    this.$store.dispatch('pullProduct', this.$route.params.id);
  },
  computed: {
    curProduct() {
      return this.$store.getters.getCurrentProduct;
    },
    curProductImg() {
      return this.$store.getters.getCurrentProductImgUrl;
    },
    curProductQuantity() {
      return this.$store.getters.getCurrentProductQuantity;
    },
  },
  methods: {
    buy() {
      this.$store.commit('addToCart');
    },
    remove() {
      this.$store.commit('removeFromCart', this.$route.params.id);
    }
  }
}
</script>