Skip to content

Instantly share code, notes, and snippets.

@ErikCH
Created January 14, 2022 03:52
Show Gist options
  • Save ErikCH/5185adc78033fda37062291ea26f920b to your computer and use it in GitHub Desktop.
Save ErikCH/5185adc78033fda37062291ea26f920b to your computer and use it in GitHub Desktop.
App.vue for Renderless Component Video
<script lang="ts" setup>
import FetchJson from "./components/fetch-json.vue";
// import { useFetch } from "@vueuse/core";
const url = "https://api.thecatapi.com/v1/images/search";
// const { isFetching: loading, error, data: response } = useFetch(url).json();
</script>
<template>
<h3>Random Cat Pics!</h3>
<fetch-json :url="url" #="{ res: response, loading }">
<div v-if="loading">
<h1>Loading...</h1>
</div>
<div v-if="response && response[0]">
<img :src="response[0].url" alt="" srcset="" />
</div>
</fetch-json>
</template>
<style>
#app {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
img {
width: 30%;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment