Skip to content

Instantly share code, notes, and snippets.

@digitalsparky
Forked from ErikCH/fetch-json.vue
Created January 14, 2022 14:30
Show Gist options
  • Save digitalsparky/48351e41f7816a426fe128550454d30d to your computer and use it in GitHub Desktop.
Save digitalsparky/48351e41f7816a426fe128550454d30d to your computer and use it in GitHub Desktop.
<script setup lang="ts">
import { ref, useSlots, getCurrentInstance } from "vue";
const props = defineProps<{ url: string }>();
const slots = useSlots();
let res = ref("");
let loading = ref(true);
fetch(props.url)
.then(response => response.json())
.then(response => {
res.value = response;
loading.value = false;
});
getCurrentInstance().render = () =>
slots.default({
res: res.value,
loading: loading.value
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment