Files
phundrak.com/content/.vuepress/components/ApiLoader.vue
T

37 lines
759 B
Vue
Raw Normal View History

<template>
2023-05-08 03:34:48 +02:00
<slot v-if="loading" name="loader">
2024-06-20 09:27:59 +02:00
<LoaderAnimation />
2023-05-08 03:34:48 +02:00
</slot>
2023-05-08 18:04:30 +02:00
<slot v-else-if="error" name="error">
2024-06-20 09:27:59 +02:00
<FetchError :url="props.url" />
</slot>
2023-05-08 18:04:30 +02:00
<slot v-else> </slot>
</template>
<script setup lang="ts">
2024-06-20 09:27:59 +02:00
import LoaderAnimation from './LoaderAnimation.vue';
import FetchError from './FetchError.vue';
2024-06-20 09:27:59 +02:00
import { useFetchAndCache } from '../composables/fetchAndCache';
const props = defineProps({
url: {
2024-06-20 09:27:59 +02:00
default: '',
required: true,
type: String,
},
cacheName: {
required: true,
type: String,
},
alreadyKnownData: Object,
});
2024-06-20 09:27:59 +02:00
const emits = defineEmits(['loaded', 'error', 'loading']);
2024-06-20 09:27:59 +02:00
const { loading, error } = useFetchAndCache(props.url, {
emits: emits,
cacheName: props.cacheName,
});
</script>