Skip to content

Instantly share code, notes, and snippets.

@danielkellyio
Created January 12, 2023 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielkellyio/a68632d3dec886c4a381035a6497cf6d to your computer and use it in GitHub Desktop.
Save danielkellyio/a68632d3dec886c4a381035a6497cf6d to your computer and use it in GitHub Desktop.
useFetch
import { ref } from "vue";
export const useFetch = (url) => {
const loading = ref(true);
const data = ref(null);
async function fetchData() {
const res = await fetch(url);
const d = await res.json();
data.value = d;
loading.value = false;
}
fetchData();
return { loading, data };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment