2018-04-02 00:10:06 -05:00
|
|
|
<template>
|
|
|
|
<div>
|
2018-09-11 22:56:26 -05:00
|
|
|
<div v-if="food === null">
|
2018-04-02 00:10:06 -05:00
|
|
|
Loading...
|
|
|
|
</div>
|
|
|
|
<div v-else>
|
2018-09-11 22:56:26 -05:00
|
|
|
<food-show :food="food"></food-show>
|
2018-04-02 00:10:06 -05:00
|
|
|
</div>
|
|
|
|
|
2024-10-02 14:34:50 -05:00
|
|
|
<router-link v-if="appConfig.isLoggedIn" class="button" :to="{name: 'edit_food', params: { id: foodId }}">Edit</router-link>
|
2018-09-11 22:56:26 -05:00
|
|
|
<router-link class="button" to="/foods">Back</router-link>
|
2018-04-02 00:10:06 -05:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2024-10-02 14:34:50 -05:00
|
|
|
<script setup>
|
2018-04-02 00:10:06 -05:00
|
|
|
|
2024-10-02 14:34:50 -05:00
|
|
|
import { computed, onBeforeMount, ref } from "vue";
|
|
|
|
import { useRoute } from "vue-router";
|
2018-09-11 22:56:26 -05:00
|
|
|
import FoodShow from "./FoodShow";
|
2018-04-02 00:10:06 -05:00
|
|
|
import api from "../lib/Api";
|
2024-10-02 14:34:50 -05:00
|
|
|
import { useLoadResource } from "../lib/useLoadResource";
|
|
|
|
import { useAppConfigStore } from "../stores/appConfig";
|
|
|
|
|
|
|
|
const { loadResource } = useLoadResource();
|
|
|
|
const appConfig = useAppConfigStore();
|
|
|
|
const route = useRoute();
|
|
|
|
|
|
|
|
const food = ref(null);
|
|
|
|
const foodId = computed(() => route.params.id);
|
|
|
|
|
|
|
|
onBeforeMount(() => {
|
|
|
|
loadResource(
|
|
|
|
api.getFood(foodId.value)
|
|
|
|
.then(data => { food.value = data; return data; })
|
|
|
|
);
|
|
|
|
});
|
2018-04-02 00:10:06 -05:00
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
</style>
|