File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
2
<main class =" mb-8" >
3
+ <div class =" flex items-center justify-center" >
4
+ <input
5
+ class =" mt-8 border border-gray-200 card bg-gray-50 focus:outline-none focus:ring-2 focus:ring-[#12b488] justify-center p-2"
6
+ placeholder =" Search meals..."
7
+ v-model =" filterText"
8
+ />
9
+ </div >
3
10
<div class =" mt-6 gap-6 grid sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4" >
4
- <div v-for =" recipe in recipes " :key =" recipe.id" >
11
+ <div v-for =" recipe in filteredMeals " :key =" recipe.id" >
5
12
<MenuCard :recipe =" recipe" />
6
13
</div >
7
14
</div >
8
15
</main >
9
16
</template >
10
17
11
18
<script setup lang="ts">
19
+ const filterText = ref (" " );
20
+
12
2
9934
1
definePageMeta ({
13
22
layout: " menu" ,
14
23
});
@@ -20,6 +29,14 @@ useHead({
20
29
const { data } = await useFetch <Recipe []>(" api/food/menus" );
21
30
22
31
const recipes: Recipe [] = data .value || [];
32
+
33
+ const filteredMeals = computed (() =>
34
+ recipes .filter (
35
+ (
36
+ meal // Ingen .value här på recipes
37
+ ) => meal .name .toLowerCase ().includes (filterText .value .toLowerCase ()) // använd filterText här istället
38
+ )
39
+ );
23
40
</script >
24
41
25
42
<style scoped>
You can’t perform that action at this time.
0 commit comments