mirror of
https://github.com/rjNemo/meal_planner
synced 2026-06-06 02:26:49 +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">
|
||||
const props = defineProps<{
|
||||
defineProps<{
|
||||
title: string;
|
||||
pictureUrl: string;
|
||||
videoUrl: string;
|
||||
|
|
|
|||
|
|
@ -7,22 +7,28 @@ type Recipe = {
|
|||
};
|
||||
|
||||
export default async function () {
|
||||
const { data, error } = await useAsyncData("random", () => {
|
||||
const config = useRuntimeConfig();
|
||||
return $fetch(`${config.apiUrl}random.php`);
|
||||
});
|
||||
const { data, pending, error } = await useAsyncData(
|
||||
"random",
|
||||
() => {
|
||||
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>({
|
||||
title: tmp?.strMeal,
|
||||
pictureUrl: tmp?.strMealThumb,
|
||||
videoUrl: tmp?.strYoutube,
|
||||
category: tmp?.strCategory,
|
||||
origin: tmp?.strArea,
|
||||
title: tmp.value.strMeal,
|
||||
pictureUrl: tmp.value.strMealThumb,
|
||||
videoUrl: tmp.value.strYoutube,
|
||||
category: tmp.value.strCategory,
|
||||
origin: tmp.value.strArea,
|
||||
});
|
||||
|
||||
return {
|
||||
recipe,
|
||||
pending,
|
||||
error,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,4 +16,4 @@ export default defineNuxtConfig({
|
|||
public: {},
|
||||
},
|
||||
ssr: true,
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<div>
|
||||
<h1 class="text-5xl font-bold prose">Eat Something New</h1>
|
||||
<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
|
||||
</NuxtLink>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
<script setup lang="ts">
|
||||
const { recipe, error } = await useRecipe();
|
||||
const { recipe, pending, error } = await useRecipe();
|
||||
</script>
|
||||
|
||||
<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>
|
||||
<div class="card w-96 bg-base-100 shadow-xl">
|
||||
<RecipeCard
|
||||
:title="recipe.title"
|
||||
:pictureUrl="recipe.pictureUrl"
|
||||
:videoUrl="recipe.videoUrl"
|
||||
:picture-url="recipe.pictureUrl"
|
||||
:video-url="recipe.videoUrl"
|
||||
:category="recipe.category"
|
||||
:origin="recipe.origin"
|
||||
/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue