Created
January 12, 2023 19:28
-
-
Save danielkellyio/a68632d3dec886c4a381035a6497cf6d to your computer and use it in GitHub Desktop.
useFetch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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