Skip to content

Commit 9792018

Browse files
committed
⭐ feat: add favor state for card card
1 parent 3738013 commit 9792018

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

assets/heartFilled.png

10.8 KB
Loading

assets/heartOutline.png

17.3 KB
Loading

components/Car/Card.vue

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
<script setup>
2+
import heartFilled from "@/assets/heartFilled.png";
3+
import heartOutline from "@/assets/heartOutline.png";
4+
25
const props = defineProps({ car: Object });
6+
7+
const favored = useState("favored-${props.car.id}", () => {
8+
return false;
9+
});
310
</script>
411

512
<template>
613
<div
7-
class="shadow border w-full overflow-hidden mb-5 cursor-pointer h-[200px]"
14+
class="relative shadow border w-full overflow-hidden mb-5 cursor-pointer h-[200px]"
815
>
16+
<img
17+
class="absolute w-7 right-5 top-2 z-20"
18+
:src="favored ? heartFilled : heartOutline"
19+
alt="heart for adding to favorites"
20+
@click="favored = !favored"
21+
/>
922
<div class="flex h-full" @click="navigateTo(`/car/${car.name}-${car.id}`)">
1023
<NuxtImg :src="car.url" alt="" class="w-[300px] h-full" />
1124
<div class="p-4 flex flex-col">

0 commit comments

Comments
 (0)