-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductCard.vue
59 lines (57 loc) · 1.57 KB
/
ProductCard.vue
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
51
52
53
54
55
56
57
58
59
<template>
<div>
<nuxt-link :to="`/products/${item.id}`">
<div
class="group relative"
>
<div class="w-full min-h-auto bg-gray-200 aspect-w-1 aspect-h-1 rounded-md overflow-hidden group-hover:opacity-75 lg:h-80 lg:aspect-none">
<div class="w-auto h-full object-center object-cover bg-gray-100">
<img
alt=""
:src="item.thumbnail"
>
</div>
</div>
<div class="mt-4 flex justify-between">
<h3 class="text-sm text-gray-700 font-normal">
{{ item.title }}
</h3>
<p class="text-sm font-semibold text-gray-900">
from {{ lowestPrice.amount/100 }} {{ lowestPrice.currency_code.toUpperCase() }}
</p>
</div>
</div>
</nuxt-link>
</div>
</template>
<script>
export default {
name: 'ProductCard',
props: {
item: {
type: Object,
default () {
return {
id: 1,
title: 'Kitchen Table',
thumbnail: 'https://picsum.photos/600/600',
variants: [{ prices: [{ amount: 0 }] }]
}
}
}
},
computed: {
lowestPrice () {
const lowestPrice = this.item.variants.reduce((acc, curr) => {
return curr.prices.reduce((lowest, current) => {
if (lowest.amount > current.amount) {
return current
}
return lowest
})
}, { amount: 0 })
return lowestPrice || { amount: 10, currency_code: 'usd' }
}
}
}
</script>