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