All files / components/Admin/AdminHome BestSellersProducts.vue

100% Statements 5/5
100% Branches 2/2
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 43 44 45 46 47 48 49 50                          1x   1x   1x   3x                                           1x                
<template>
  <div class="p-3">
    <p class="text-uppercase">best sellers products</p>
    <div class="row justify-content-center w-100 m-0">
      <ProductCard
        class="col-6 p-0 m-1"
        v-for="product in products"
        :key="product.id"
        :product="product"
      />
    </div>
  </div>
</template>
 
<script>
import qs from "qs";
 
import { error } from "~/utils/error.js";
 
import ProductCard from "~/components/Admin/common/ProductCard.vue";
 
export default {
  name: "BestSellersProducts",
  data: () => ({
    products: [],
  }),
  components: { ProductCard },
  async mounted() {
    try {
      const queryData = {
        _sort: `sales:DESC`,
        _limit: 4,
      };
      const query = qs.stringify(queryData);
 
      const { data } = await this.$axios.get(`/products?${query}`);
      this.products = data;
    } catch (e) {
      error(e);
    }
  },
};
</script>
 
<style scoped>
.col-6 {
  flex: 0 0 48%;
  max-width: 48%;
}
</style>