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

37 lines
759 B
Vue
Raw Normal View History

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