File tree Expand file tree Collapse file tree 3 files changed +42
-8
lines changed Expand file tree Collapse file tree 3 files changed +42
-8
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
- <div >food details for {{ id }}</div >
2
+ <div v-if =" recipe" >
3
+ <div >Food details for {{ id }}</div >
4
+ <div >{{ recipe.name }}</div >
5
+ </div >
6
+ <div v-else >Loading...</div >
3
7
</template >
4
8
5
9
<script setup lang="ts">
6
10
const { id } = useRoute ().params ;
7
11
definePageMeta ({
8
12
layout: " menu" ,
9
13
});
14
+
15
+ const { data : recipe } = await useFetch <Recipe >(
16
+ ` https://dummyjson.com/recipes/${id } `
17
+ );
10
18
</script >
11
19
12
20
<style scoped></style >
Original file line number Diff line number Diff line change 1
1
<template >
2
- <div >
3
- <h2 >Food</ h2 >
4
- < p >
5
- Lorem ipsum dolor sit amet consectetur adipisicing elit. Vitae temporibus
6
- repellat commodi voluptatem laborum atque nobis eum at. Nesciunt, culpa.
7
- </p >
8
- </div >
2
+ <main >
3
+ <div class = " grid grid-cols-4 gap-5 " >
4
+ < div v-for = " recipe in recipes " :key = " recipe.id " >
5
+ < NuxtLink :to = " `/menu/${recipe.id}` " >{{ recipe.name }}</ NuxtLink >
6
+ </ div >
7
+ </div >
8
+ </main >
9
9
</template >
10
10
11
11
<script setup lang="ts">
12
12
definePageMeta ({
13
13
layout: " menu" ,
14
14
});
15
+
16
+ // Hämtar recept
17
+ const { data } = await useFetch <{ recipes: Recipe [] }>(
18
+ " https://dummyjson.com/recipes"
19
+ );
20
+
21
+ const recipes: Recipe [] = data .value ?.recipes || [];
22
+ console .log (recipes );
15
23
</script >
16
24
17
25
<style scoped>
Original file line number Diff line number Diff line change
1
+ interface Recipe {
2
+ id : number ;
3
+ name : string ;
4
+ caloriesPerServing : number ;
5
+ cookTimeMinutes : number ;
6
+ cuisine : string ;
7
+ difficulty : string ;
8
+ image : string ;
9
+ ingredients : string [ ] ;
10
+ instructions : string [ ] ;
11
+ mealType : string [ ] ;
12
+ prepTimeMinutes : number ;
13
+ rating : number ;
14
+ reviewCount : number ;
15
+ servings : number ;
16
+ tags : string [ ] ;
17
+ userId : number ;
18
+ }
You can’t perform that action at this time.
0 commit comments