mirror of
https://github.com/rjNemo/meal_planner
synced 2026-06-12 13:26:45 +00:00
design card component
This commit is contained in:
parent
9cc1f83dc0
commit
44beb6f61b
6 changed files with 73 additions and 12 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
29
components/recipe/card.vue
Normal file
29
components/recipe/card.vue
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
const props = defineProps<{
|
||||||
|
title: string;
|
||||||
|
pictureUrl: string;
|
||||||
|
videoUrl: string;
|
||||||
|
category: string;
|
||||||
|
origin: string;
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="card-body items-center text-center">
|
||||||
|
<h2 class="card-title">{{ title }}</h2>
|
||||||
|
<figure class="px-10 py-5">
|
||||||
|
<NuxtImg :src="pictureUrl" alt="Shoes" class="rounded-xl" />
|
||||||
|
</figure>
|
||||||
|
<div class="card-actions space-between">
|
||||||
|
<NuxtLink class="badge badge-outline" :to="videoUrl">
|
||||||
|
<Icon name="cib:youtube" color="red" />
|
||||||
|
</NuxtLink>
|
||||||
|
<div class="badge badge-secondary">
|
||||||
|
<Icon name="cil:apple" /> {{ category }}
|
||||||
|
</div>
|
||||||
|
<div class="badge badge-secondary">
|
||||||
|
<Icon name="cil:location-pin" /> {{ origin }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
28
composables/useRecipe.ts
Normal file
28
composables/useRecipe.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
type Recipe = {
|
||||||
|
title: string;
|
||||||
|
pictureUrl: string;
|
||||||
|
videoUrl: string;
|
||||||
|
category: string;
|
||||||
|
origin: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function () {
|
||||||
|
const { data, error } = await useAsyncData("random", () => {
|
||||||
|
const config = useRuntimeConfig();
|
||||||
|
return $fetch(`${config.apiUrl}random.php`);
|
||||||
|
});
|
||||||
|
|
||||||
|
const tmp = data.value?.meals?.[0];
|
||||||
|
const recipe = reactive<Recipe>({
|
||||||
|
title: tmp?.strMeal,
|
||||||
|
pictureUrl: tmp?.strMealThumb,
|
||||||
|
videoUrl: tmp?.strYoutube,
|
||||||
|
category: tmp?.strCategory,
|
||||||
|
origin: tmp?.strArea,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
recipe,
|
||||||
|
error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
devtools: { enabled: true },
|
devtools: { enabled: true },
|
||||||
css: ["~/assets/css/main.css"],
|
css: ["~/assets/css/main.css"],
|
||||||
modules: ["@nuxt/eslint", "@nuxt/image"],
|
modules: ["@nuxt/eslint", "@nuxt/image", "nuxt-icon"],
|
||||||
postcss: {
|
postcss: {
|
||||||
plugins: {
|
plugins: {
|
||||||
tailwindcss: {},
|
tailwindcss: {},
|
||||||
|
|
@ -16,4 +16,4 @@ export default defineNuxtConfig({
|
||||||
public: {},
|
public: {},
|
||||||
},
|
},
|
||||||
ssr: true,
|
ssr: true,
|
||||||
});
|
});
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
"@nuxt/eslint": "^0.3.10",
|
"@nuxt/eslint": "^0.3.10",
|
||||||
"@nuxt/image": "^1.6.0",
|
"@nuxt/image": "^1.6.0",
|
||||||
"nuxt": "^3.11.2",
|
"nuxt": "^3.11.2",
|
||||||
|
"nuxt-icon": "^0.6.10",
|
||||||
"vue": "^3.4.21",
|
"vue": "^3.4.21",
|
||||||
"vue-router": "^4.3.0"
|
"vue-router": "^4.3.0"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,18 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const { data, pending, error, refresh } = await useFetch(
|
const { recipe, error } = await useRecipe();
|
||||||
"https://www.themealdb.com/api/json/v1/1/random.php",
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div v-if="error">Failed: {{ error }}</div>
|
||||||
<div v-if="pending">Loading</div>
|
<section v-else>
|
||||||
<div v-else-if="error">Failed: {{ error }}</div>
|
<div class="card w-96 bg-base-100 shadow-xl">
|
||||||
<pre v-else>
|
<RecipeCard
|
||||||
{{ data?.meals?.[0] }}
|
:title="recipe.title"
|
||||||
</pre>
|
:pictureUrl="recipe.pictureUrl"
|
||||||
</div>
|
:videoUrl="recipe.videoUrl"
|
||||||
|
:category="recipe.category"
|
||||||
|
:origin="recipe.origin"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue