mirror of
https://github.com/rjNemo/meal_planner
synced 2026-06-12 05:16:47 +00:00
fix: client side navigation
This commit is contained in:
parent
44beb6f61b
commit
bd5fe9be95
5 changed files with 24 additions and 17 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const props = defineProps<{
|
defineProps<{
|
||||||
title: string;
|
title: string;
|
||||||
pictureUrl: string;
|
pictureUrl: string;
|
||||||
videoUrl: string;
|
videoUrl: string;
|
||||||
|
|
|
||||||
|
|
@ -7,22 +7,28 @@ type Recipe = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function () {
|
export default async function () {
|
||||||
const { data, error } = await useAsyncData("random", () => {
|
const { data, pending, error } = await useAsyncData(
|
||||||
const config = useRuntimeConfig();
|
"random",
|
||||||
return $fetch(`${config.apiUrl}random.php`);
|
() => {
|
||||||
});
|
const config = useRuntimeConfig();
|
||||||
|
return $fetch(`${config.apiUrl}random.php`);
|
||||||
|
},
|
||||||
|
{ lazy: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
const tmp = computed(() => data.value?.meals?.[0]);
|
||||||
|
|
||||||
const tmp = data.value?.meals?.[0];
|
|
||||||
const recipe = reactive<Recipe>({
|
const recipe = reactive<Recipe>({
|
||||||
title: tmp?.strMeal,
|
title: tmp.value.strMeal,
|
||||||
pictureUrl: tmp?.strMealThumb,
|
pictureUrl: tmp.value.strMealThumb,
|
||||||
videoUrl: tmp?.strYoutube,
|
videoUrl: tmp.value.strYoutube,
|
||||||
category: tmp?.strCategory,
|
category: tmp.value.strCategory,
|
||||||
origin: tmp?.strArea,
|
origin: tmp.value.strArea,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
recipe,
|
recipe,
|
||||||
|
pending,
|
||||||
error,
|
error,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,4 @@ export default defineNuxtConfig({
|
||||||
public: {},
|
public: {},
|
||||||
},
|
},
|
||||||
ssr: true,
|
ssr: true,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
<div>
|
<div>
|
||||||
<h1 class="text-5xl font-bold prose">Eat Something New</h1>
|
<h1 class="text-5xl font-bold prose">Eat Something New</h1>
|
||||||
<p class="py-6 prose">Generate a random recipe.</p>
|
<p class="py-6 prose">Generate a random recipe.</p>
|
||||||
<NuxtLink to="/random" class="btn btn-primary">
|
<NuxtLink to="/random" class="btn btn-primary" external>
|
||||||
Random Recipe Now
|
Random Recipe Now
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const { recipe, error } = await useRecipe();
|
const { recipe, pending, error } = await useRecipe();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-if="error">Failed: {{ error }}</div>
|
<div v-if="pending">Loading</div>
|
||||||
|
<div v-else-if="error">Failed: {{ error }}</div>
|
||||||
<section v-else>
|
<section v-else>
|
||||||
<div class="card w-96 bg-base-100 shadow-xl">
|
<div class="card w-96 bg-base-100 shadow-xl">
|
||||||
<RecipeCard
|
<RecipeCard
|
||||||
:title="recipe.title"
|
:title="recipe.title"
|
||||||
:pictureUrl="recipe.pictureUrl"
|
:picture-url="recipe.pictureUrl"
|
||||||
:videoUrl="recipe.videoUrl"
|
:video-url="recipe.videoUrl"
|
||||||
:category="recipe.category"
|
:category="recipe.category"
|
||||||
:origin="recipe.origin"
|
:origin="recipe.origin"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue